Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I just updated a menu on a site of mine to utilize wp_nav_menu. Setting this up with WP was fairly straight forward however I've run into one small snag with the the way wordpress is outputting its parent/ancestor classes for use in highlighting the current page that the content belongs to, particularly with single post pages...

Highlighting the current page with .current_page_item a and .current_page_parent a works perfect as long as its just on a normal page with children, however as soon as you visit a post from events or media, the blog link in the menu is highlighted instead which is incorrect obviously.

*One thing noticeably wrong when looking at Wordpress' output is that the current page classes are not even being generated on the correct li tag that the post belongs to which seems to be the root of the problem.

For future reference, the Events, Media, & Blog pages all use a special query I've written to only grab the respective category for that page, ie.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("category_name=media&paged=$paged");

if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post">
</div>
<?php
endwhile;
else:
endif;

It should be noted: I have a secondary loop in the footer grabbing the latest blog post, dunno if this could be the culprit but Id like to keep that as is since it was placed there upon request of the client.

-- I take it back, I removed the secondary loop in the footer to see what would happen and the same results occurred so its not the problem as far as I can tell.

Hope thats enough info, if not let me know. Best, SB

share|improve this question
1  
I think this might solve your problem: stackoverflow.com/questions/3269878/… Best of luck! –  Michelle Aug 1 '11 at 17:54
    
Thank you, this looks useful but Im not using "Custom Post-Types" –  Mr.Brown Aug 1 '11 at 18:02
    
Have you tried using the menu system in Appearance > Menus instead of using your custom query? It would allow you to add "Media" and "Events" as category archive pages and "Blog" as either a category archive page or a Page (either one set to display recent posts in Settings > Reading or one using a custom page template). –  Michelle Aug 1 '11 at 20:41
    
I considered that but I didn't want to have the url appear as a category. Is that my only option then basically?..assuming with categories the correct parent will highlight.. –  Mr.Brown Aug 1 '11 at 21:04
    
So I tried using category/media & category/events in the menu instead with some new category templates I put together and no dice still. The pages appear the same and grab the posts correctly but the incorrect current page classes are still being outputted by wordpress on the blog link instead so Im stuck in the same place as before. –  Mr.Brown Aug 1 '11 at 21:51

1 Answer 1

This works for me:

  1. Create a Page called "Blog" and in Settings > Reading, set the Blog Page to be the Posts page.
  2. Create a WordPress menu and add to it my Blog Page, Category 1 and Category 2
  3. Navigate to one of the posts in Category 1
  4. Category 1 is set as "current-post-parent" in the menu

You can remove "category" from the URL using one of the various methods out there (plugin, permalink structure, .htaccess). I just tried using the permalink structure method and that worked fine.

Hope this works - keeping my fingers crossed & knocking on wood & all that good stuff! :)

share|improve this answer
    
Ok, let me make sure I understand... 1. Make a blog page template separate from the index.php, choose static front page in the reading settings, and then make the blog page the posts page? (Im actually already doing this with my index.php file) 2. Create a new WP Menu, and add the Blog page along with a Media Category & Events Category page instead of using the media.php/events.php templates? 3. & 4. you lost me here.... –  Mr.Brown Aug 2 '11 at 23:20
    
Does the "blog" page show only posts in the category "blog"? As opposed to posts from all of your categories? If so, then you can skip creating a WordPress page and just add it to the Menu as a category, just like Events and Media. You can skip step 1 if that is the case, and add all three as "categories" to the menu. #3 and #4 above are just to test that this works correctly. –  Michelle Aug 3 '11 at 16:07
    
Ok, yes. My blog page is as you described: a normal page that only shows the blog category. I basically have a wp_query for each page that only grabs 1 category, ie. Events, Media, Blog. I had tried placing the events & media into the menu as categories instead of pages previuously but not for the the blog page since I thought my landing page would not be correct then, no? In other words, in my reading settings - I have my events page set to "Front Page", and my blog page set to "Posts Page"...so when you arrive at the site you see the events feed, but if I were to add the category "blog".. –  Mr.Brown Aug 3 '11 at 17:02
    
(meant to say if I were to add the category "events"...)...instead, wouldnt that url be a "category/events" rather then just the root, ie. www.mysite.com ? So that wouldnt work in theory it seems. –  Mr.Brown Aug 3 '11 at 17:19
    
Have you tried my suggestion and it didn't work? –  Michelle Aug 3 '11 at 17:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.