change the elements in the wp menu - wordpress

how can I change the element structure of the menu in wordpress themes? like I want to change the structure into this:
<nav id="mymenu" class="menu"> <!-- here the li tags with links --></nav>
just want to replace the UL tags with the nav tags which is html5. Thanks.

You will have to use the items_wrap parameter in wp_nav_menu to achieve this.
There is an example in this page
http://codex.wordpress.org/Function_Reference/wp_nav_menu
under the heading "Removing the ul wrap"

It's worth noting that you wouldn't want to use <li></li> elements outside of a <ul> or <ol> element - it's not valid HTML. What you probably want to do is wrap the list in a nav tag.
I'm assuming, since you're asking this question, that you're using WP's auto-generated menu? You can change a bunch of variables - check the WordPress Codex (always): http://codex.wordpress.org/Function_Reference/wp_nav_menu

Related

How to style a list under div class in css?

Im very new to html and css, and I am having trouble accessing this list to edit in css:
<div id="content">
<div id="recent-users">
<ul id="recent-user-list">
<li class="user">Bob Bobalooba</li>
<li class="user">Mary Contrary</li>
<li class="user">James Bean</li>
<li class="user">Jim Jimbulator</li>
</ul>
</div>
</div>
I've tried many variations of things like #recent-users-list, #content #recent-users #recent-users-list li a etc and I havent been able to find any other posts that have helped witht his specific situation.
Thankyou in advance for any help.
First of all, accessing elements via ids are done with hash # and classes with period .. They are not interchangeably.
You are not using commas to select underlying elements. Commas actually allow you to select multiple different elements at once.
You can directly access the list via:
#recent-user-list
Or its children li elements via:
#recent-user-list .user
Or its grandchildren li a elements via:
#recent-user-list .user a
Documentation can be found here:
https://www.w3schools.com/cssref/css_selectors.asp

Sub menus not showing in hierarchical

I have added a new custom menu but sub menus not showing in hierarchical.
I want to display animal and automotive categories under More.
Anyone can help me?
The page I need help with: bit.ly/2Dz5EWB
First of all your sub-menu is opening on hovering <div class="cat-menu"> this element.
You need to remove this kind of CSS.
There is one unique class in list item .menu-item-has-children which has sub-menu for categories.
You just need to set hover CSS for this list item like:
.cat-menu ul li.menu-item-has-children:hover .sub-menu{
display:block;
}
<ul class="sub-menu"> is inside the <li class="menu-item-has-children"> this element so you need to set CSS like above code.
I hope this will be helpful for you.

Change css for the current selected li

I have this menu:
<div id="menu-home">
<ul>
<li> a </li>
</ul>
</div>
When I am on the test.php page that corresponds to test menu, I need it's li to have a different style..
I tried
#menu-home ul li:active
but it didn't work..
Thanks
There is no :active state for <li>
Instead you can do it with PHP.
<div id="menu-home">
<ul>
<li <?php if (page is current page) echo ' class="active"';?>> a </li>
</ul>
</div>
And in the CSS, you can give this:
#menu-home ul li.active {}
The <li> element does not have an active state, since it is just meant to be a (stateless) bullet point. The selector :active can only be used on a link; an example can be found here.
However, :active will only highlight the link as it is clicked. After that, it performs whatever action and/or navigation it is set to do and then the link will be visited. From there on you can't tell it apart from the other already visited pages that you are not currently viewing and it does not become "unvisited" again, even if you navigate to another page. So this does not do what you intend.
Instead, I would create a class .active in your CSS where you can define all your custom styling. Then, the PHP that generates your pages needs to take care of setting the class correctly on the selected menu item, ie.: attach class="active" it either to the <li> or the <a> whenever the menu is build.
(yeah, just see Praveen's answer for the code ^^)

How can you create a cross browser css menu that doesnt require you to provide a style for EVERY LEVEL of the menu

I have a menu that will be automatically created in an asp.net page. I'm trying to use a pure CSS cross browser menu but how can i set it so that each subsequent child is autohiden/shown w/o having to define the style for each level of the menu.
Is this the only way to accomplish this with css?
Essentially im looking for a way to use css to show/hide the child menu items w/o having to define the style for every level - especially since i dont know how many levels there will be.
you should be able to do it by only specifying down to the second level
<html>
<head>
<style>
.mnusub li ul{ display:none; }
.mnusub li:hover > ul{ display: block; }
</style>
</head>
<body>
<ul class="mnusub">
<li>test1
<ul class="mnusub">
<li>test2</li>
<li>test11
<ul class="mnusub">
<li>test3</li>
<li>test4</li>
<li>test5</li>
</ul>
</li>
</ul>
</li>
<li>test5
<ul class="mnusub">
<li>test6</li>
<li>test7</li>
<li>test8</li>
</ul>
</li>
<li>test9</li>
<li>test10</li>
</ul>
</body>
</html>
The key here is the ">" selector as it specifies direct descendants and not sub-descendants
enjoy
When you want to affect each child individually, but without having to make style rules for each of those children, then you need more logic, which CSS doesn't provide. You could use something like PHP for that logic, or you could go with Javascript/jQuery. In that case, you can toggle CSS classes on child[x] through jQuery, and you only need to style those classes. Then it wouldn't matter which child got the class, it would be styled accordingly. Note that you should first make sure your menu is at least usable without Javascript, so users aren't dependent upon it.

SIFR'ing <LI> parents only

I'm using SIFR 3.0 in combination with suckerfish popup menus. I only want to SIFR the top level li's and not apply the effect to the nested ones. I'm also using WordPress, so restructuring the menu, like wrapping the parent in a <div> or other object is too hard (I'm still figuring out the basics of WordPress).
Is there a way to turn SIFR
ON for ul#menu li
but OFF for ul#menu li li ?
Other things I've tried that haven't worked is applying a class or id to the parent <li class="top-level"> or <li id="top-level">--that didn't stop the SIFR, it still grabbed the children.
Thanks so much for the help.
I'm going to assume your HTML structure is like this:
<ul id="menu">
<li>
My link
<ul>
<li>My submenu item</li>
</ul>
</li>
</ul>
When you replace ul#menu li, you will replace the entire content of the <li> element. Unfortunately this also includes the submenu. The solution is to replace just the link, but note that you can't directly replace <a> elements.
Therefore:
<ul id="menu">
<li>
<span>My link</span>
<ul>
<li>My submenu item</li>
</ul>
</li>
</ul>
And replace ul#menu > li span.
Finally there is the question whether the Suckerfish menus actually work if the events have to come through sIFR. I suspect it won't, meaning you're probably better off not using sIFR here.
This can be done with the CSS child selector:
ul#menu > li
this will only select li elements that are direct children of ul#menu. This should work in all standards complient browsers, and IE7+.
For IE6 there are a few hacks you can do to fake it, although I prefer to use jQuery to make up for selectors it doesn't support:
$('ul#menu > li').css({ ... });
which you can place in conditional comments.
If you download the uncompressed sifr source, and also have jQuery or are good with javascript you can probably put a conditional in at around line 491 of the sifr code along the lines of
if ($(node).parent().parent().parent().attr('id', 'menu')) {continue;}
I'm not great at jQuery, and I'm also not sure what kind of object the nodes that sifr runs through are, but in theory something like the above should make waht you want possible.

Resources