I generate a menu in Wordpress that has three layers. I do that with the code:
wp_nav_menu(array('theme_location' => 'primary', 'menu_class' => 'SecondaryNavigation'));
Wordpress generates a menu like this:
<div class="menu-mainnavigation_de-container">
<ul id="menu-mainnavigation_de" class="SecondaryNavigation">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-39">
Home
<ul class="sub-menu">
<li id="menu-item-44" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-44">Einführung</li>
<li id="menu-item-43" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-43">Aktuelles</li>
</ul>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-30 current_page_item current-menu-ancestor current-menu-parent current_page_parent current_page_ancestor menu-item-has-children menu-item-40">
Der Tell
<ul class="sub-menu">
<li id="menu-item-42" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-30 current_page_item menu-item-42">Beschreibung</li>
<li id="menu-item-41" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-41">Topographie</li>
</ul>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-51">
Forschung
<ul class="sub-menu">
<li id="menu-item-53" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-53">Forschungsgeschichte</li>
<li id="menu-item-52" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-52">Forschungsprobleme</li>
</ul>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-65">
Kampagnen
<ul class="sub-menu">
<li id="menu-item-64" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-64">
Ausgrabung 2010
<ul class="sub-menu">
<li id="menu-item-63" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-63">Grabungsstelle C – Haus I (Sq. 6644-5, 6744-6 & 6844-6)</li>
</ul>
</li>
</ul>
</li>
</ul>
I have to divide the menu into two menues: In the header on the top, only the first layer of the menu is visible. This is very easy with the depth-call of wp_nav_menu and works just fine.
In the Sidebar I want to display the corresponding second and third level (everything under the class .sub-menu) of the menu, depending what was selected in the header. I tried to do this via CSS with the two simple lines:
.SecondaryNavigation {
display: none;
}
.SecondaryNavigation .current-menu-ancestor .sub-menu {
display: block;
}
Unfortunately, this does not work. How can I display only the second and third level of my menu, depending on what was selected in the primary level? Wordpress assigns the corresponding classes, like .current-menu-ancestor or .sub-menu, so it must be possible in some way, right?
Thanks for your help!
All the best
Sebastian
I would simply create the secondary menus and then list on the pages accordingly, which will be quite simple and effective.
Let me know if you need further help.
Related
I am trying to making a responsive menu, that takes on full width in the sub's sub-menu but my problem is that it is restricted to the parent li which is 33.3%, I want my submenu of the submenu to be 100% width as well. Here is my codepen
and my code as follows
<div class="mobile-menu hidden-lg-up active">
<ul id="menu-mobile-menu" class="links-middle-group">
<li id="menu-item-31" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-31">About
<ul class="sub-menu">
<li id="menu-item-70" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-70">Section 1
<ul class="sub-menu">
<li id="menu-item-72" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-72">Sub section 1</li>
<li id="menu-item-71" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-71">Sub section 2</li>
<li id="menu-item-73" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-73">Sub section 3</li>
</ul>
</li>
<li id="menu-item-33" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-33">Section 2</li>
<li id="menu-item-41" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-41">Section 3</li>
</ul>
</li>
<li id="menu-item-35" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-35">Portfolio
<ul class="sub-menu">
<li id="menu-item-42" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-42">Portfolio 1</li>
<li id="menu-item-43" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-43">Portfolio 2</li>
<li id="menu-item-44" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-44">Portfolio 3</li>
</ul>
</li>
<li id="menu-item-37" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-37">Contact
<ul class="sub-menu">
<li id="menu-item-30" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-30">facebook</li>
<li id="menu-item-65" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-65">Twitter</li>
<li id="menu-item-34" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-34">Email me</li>
</ul>
</li>
</ul>
</div>
The menu heading of sub section 1, 2 and 3 will have it's own column, so restricting to height cannot work. Each section when clicked on will display it's own section (not demostarted in demo) I also tried position but that makes the second link portfolio jumps up and ruin the layout.Maybe I am doing it wrong?
Since your list items are 33% of the full width, the nested list at most can take up the width of its parent. Since it's 100% of 33%, you could set the width of your nested .sub-menu's to 300%.
.sub-menu .sub-menu {
width: 300%;
}
I'd also recommend creating another class name for targeting nested sub-menu's because this selector looks a bit funny.
Note: This isn't the best for maintainability since you'd need to update it whenever you added or removed list items, and it relies on an assumption of how many list items are there. Absolutely positioning the nested sub-menu within a relatively-positioned .menu-item would work best but then you'd need to know the height of the list items. Although that's a lot easier to maintain than width.
At this page, there is a vertical menu in the left column. Some of the nav menu items have flyout submenu items. I'd like to place a right arrow (http://www.salsalis.com.au/wp-content/themes/twentyfourteen/images/rarrow.png) to the right of every LI that contains a UL.submenu, so that it looks like this, but I can't find a way to do this.
http://imgur.com/a/rJVU2
(For the last 2 months the IMG embed # stackoverflow.com seems broken)
Here is the Wordpress nav menu HTML: (messy as it is):
<div class="menu-main_menu-container">
<ul style="min-height: 600px; height: 259px;" class="sub-nav">
<li id="menu-item-24" class="home_page menu-item menu-item-type-post_type menu-item-object-page menu-item-home current-menu-item page_item page-item-5 current_page_item menu-item-24">Home</li>
<li id="menu-item-23" class="accommodation_page menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-23">Accommodation
<ul class="sub-menu">
<li id="menu-item-128" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-128">Wilderness Tents</li>
<li id="menu-item-1381" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1381">Honeymoon Tent</li>
<li id="menu-item-129" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-129">Rates</li>
<li id="menu-item-130" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-130">The Lodge</li>
<li id="menu-item-127" class="food_page menu-item menu-item-type-post_type menu-item-object-page menu-item-127">Food And Wine</li>
<li id="menu-item-126" class="location_page menu-item menu-item-type-post_type menu-item-object-page menu-item-126">Location</li>
<li id="menu-item-125" class="getting_page menu-item menu-item-type-post_type menu-item-object-page menu-item-125">Getting There</li>
</ul>
</li>
<li id="menu-item-124" class="experiance_page menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-124">Experience
<ul class="sub-menu">
<li id="menu-item-967" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-967">Wave Rider</li>
<li id="menu-item-122" class="whale_page menu-item menu-item-type-post_type menu-item-object-page menu-item-122">Whale Shark Swim</li>
<li id="menu-item-835" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-835">Humpback Swim</li>
<li id="menu-item-121" class="snorkelling_page menu-item menu-item-type-post_type menu-item-object-page menu-item-121">Snorkelling</li>
<li id="menu-item-120" class="guidgorge_page menu-item menu-item-type-post_type menu-item-object-page menu-item-120">Guided Walks</li>
<li id="menu-item-119" class="kayaking_page menu-item menu-item-type-post_type menu-item-object-page menu-item-119">Kayaking</li>
<li id="menu-item-118" class="fising_page menu-item menu-item-type-post_type menu-item-object-page menu-item-118">Fishing</li>
</ul>
</li>
<li id="menu-item-165" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-165">Special Offers
<ul class="sub-menu">
<li id="menu-item-183" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-183">Sail and Snorkel Ningaloo</li>
<li id="menu-item-1654" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1654">Private Charter Flight Packages</li>
</ul>
</li>
<li id="menu-item-117" class="about_page menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-117">About Us
<ul class="sub-menu">
<li id="menu-item-116" class="ecocre_page menu-item menu-item-type-post_type menu-item-object-page menu-item-116">Eco Credentials</li>
<li id="menu-item-1174" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1174">Sal Salis Facts</li>
<li id="menu-item-1362" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1362">Testimonials</li>
<li id="menu-item-1616" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1616">Seasonal Calendar</li>
<li id="menu-item-1218" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1218">Download Information</li>
<li id="menu-item-115" class="gallery_page menu-item menu-item-type-post_type menu-item-object-page menu-item-115">Image Gallery</li>
<li id="menu-item-114" class="terms_page menu-item menu-item-type-post_type menu-item-object-page menu-item-114">Terms And Conditions</li>
</ul>
</li>
<li id="menu-item-113" class="enquire_page menu-item menu-item-type-post_type menu-item-object-page menu-item-113">Contact Us</li>
<li id="menu-item-311" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-311">Blog</li>
</ul>
</div>
Make use of pseudo elements
Try this
CSS
ul.sub-nav > li.menu-item-has-children::after{
content: "";
position: absolute;
right: 0px;
height: 0px;
top: 0;
bottom: 0;
margin: auto;
border: 6px solid transparent;
border-left-color: #fff;
}
hope this helps..
I am working on WordPress sidebar menu, I want to get link active when click on that particular link.
<ul id="menu-home" class="menu">
<li id="menu-item-10"
class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-10">
Home
</li>
<li id="menu-item-50"
class="menu-item menu-item-type-post_type menu-item-object-page menu-item-50">
About
</li>
<li id="menu-item-48"
class="menu-item menu-item-type-post_type menu-item-object-page menu-item-48">
Services
</li>
<li id="menu-item-47"
class="menu-item menu-item-type-post_type menu-item-object-page menu-item-47">
Gallery
</li>
<li id="menu-item-49"
class="menu-item menu-item-type-post_type menu-item-object-page menu-item-49">
Contact
</li>
<li id="menu-item-235"
class="menu-item menu-item-type-post_type menu-item-object-page menu-item-235">
Blog
</li>
</ul>
Add following CSS
.current_page_item {
color: #920606
}
Change hexadecimal code based on your design
On my WordPress website I have used wp_nav_menu to create the navigation bar. Because of this I have limited control over the HTML, for one of the navigation links I have started styling it to be a dropdown. However, the CSS for the rest of the navigation bar is interfering with this, how can I modify the HTML so that I can separate the two?
HTML -
<nav class="site-nav">
<div class="menu-primary-menu-links-container"><ul id="menu-primary-menu-links" class="menu"><li id="menu-item-36" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-36">Contact</li>
<li id="menu-item-37" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-37">Tuition</li>
<li id="menu-item-38" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-28 current_page_item current_page_parent menu-item-38">Blog</li>
<li id="menu-item-107" class="test menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-107">Gallery
<ul class="sub-menu">
<li id="menu-item-119" class="menu-item menu-item-type-taxonomy menu-item-object-product_cat menu-item-119">Animals</li>
<li id="menu-item-120" class="menu-item menu-item-type-taxonomy menu-item-object-product_cat menu-item-120">Contemporary Space Images</li>
</ul>
</li>
<li id="menu-item-42" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-home menu-item-42">Home</li>
</ul>
I have created a WordPress site for a client, in which you filter through the navigation menu (set-up in appearance->menu) by revealing hidden items (unordered lists with class "sub-menu (generated through WordPress menu function)).
There are three hierarchal tiers; Pages>custom-links>Posts. When the page is clicked, the children (custom-links) are revealed, when a custom link is clicked, the children posts are revealed.
Then, when you are on a post, the path taken is highlighted in the navigation.
This is done through css and current/parent/ancestor classes generated with the wp_nav_menu function.
The mark-up generated by the wp_nav_menu function is this:
<ul id="menu-menu-2" class="main_menu"><li id="menu-item-155" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-ancestor current_page_ancestor menu-item-has-children menu-item-155">Design
<ul class="sub-menu">
<li id="menu-item-152" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-ancestor current-menu-parent menu-item-has-children menu-item-152">#DesignCat1
<ul class="sub-menu">
<li id="menu-item-207" class="menu-item menu-item-type-post_type menu-item-object-post current-menu-item menu-item-207">DesignC1P1</li>
<li id="menu-item-206" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-206">DesignC1P2</li>
</ul>
</li>
<li id="menu-item-153" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-153">#DesignCat2
<ul class="sub-menu">
<li id="menu-item-144" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-144">DesignC2P1</li>
<li id="menu-item-143" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-143">DesignC2P2</li>
</ul>
</li>
</ul>
</li>
<li id="menu-item-156" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-156">Research
<ul class="sub-menu">
<li id="menu-item-149" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-149">#ResearchCat1
<ul class="sub-menu">
<li id="menu-item-205" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-205">ResearchC1P1</li>
<li id="menu-item-204" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-204">ResearchC1P2</li>
</ul>
</li>
<li id="menu-item-150" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-150">#ResearchCat2
<ul class="sub-menu">
<li id="menu-item-140" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-140">ResearchC2P1</li>
<li id="menu-item-139" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-139">ResearchC2P2</li>
</ul>
</li>
</ul>
</li>
</ul>
The current page being "DesignC1P1", it's assigned a class of "current-menu-item", its parent (a custom link(#DesignCat1)) assigned "current-menu-parent" and its ancestor (a page(Design)) assigned "current-menu-ancestor". So, with CSS I do:
.current-menu-item > .sub-menu, .current-menu-parent > .sub-menu, .current-menu-ancestor > .sub-menu {
visibility: visible;
display: inline;
}
.current-menu-item > a, .current-menu-parent > a, .current-menu-ancestor > a {
color: #000;
text-decoration: none;
}
Which works well, it keeps all the relevant menu items visible and highlighted in black.
My issue is that my client has specifically asked for posts to be in more than one location in the menu, IE the same post could be under Design page and Research Page, or under two different custom-links in design/research. That means the same mark up is generated for the two item locations, and both paths are shown rather than the path taken. Here is what the generated code with the "Same Post" under #DesignCat1 and #ResearchCat1 would look like:
<ul id="menu-menu-2" class="main_menu"><li id="menu-item-155" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-ancestor current_page_ancestor menu-item-has-children menu-item-155">Design
<ul class="sub-menu">
<li id="menu-item-152" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-ancestor current-menu-parent menu-item-has-children menu-item-152">#DesignCat1
<ul class="sub-menu">
<li id="menu-item-202" class="menu-item menu-item-type-post_type menu-item-object-post current-menu-item menu-item-202">Same Post</li>
</ul>
</li>
<li id="menu-item-153" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-153">#DesignCat2
<ul class="sub-menu">
<li id="menu-item-144" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-144">DesignC2P1</li>
<li id="menu-item-143" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-143">DesignC2P2</li>
</ul>
</li>
</ul>
</li>
<li id="menu-item-156" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-ancestor current_page_ancestor menu-item-has-children menu-item-156">Research
<ul class="sub-menu">
<li id="menu-item-149" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-ancestor current-menu-parent menu-item-has-children menu-item-149">#ResearchCat1
<ul class="sub-menu">
<li id="menu-item-203" class="menu-item menu-item-type-post_type menu-item-object-post current-menu-item menu-item-203">Same Post</li>
</ul>
</li>
<li id="menu-item-150" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-150">#ResearchCat2
<ul class="sub-menu">
<li id="menu-item-140" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-140">ResearchC2P1</li>
<li id="menu-item-139" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-139">ResearchC2P2</li>
</ul>
</li>
</ul>
</li>
</ul>
Any ideas how to highlight only the path taken, rather than both? I know HTML,CSS and a bit of java, not so good with PHP! Any help would be greatly appreciated!