loop causes page menu to not be active
-
Here is the default page loop:
<?php if(have_posts()) { /* Start the Loop */ while (have_posts()) { the_post(); get_template_part('content', 'page'); /* Display comments */ if ( theme_get_option('theme_allow_comments')) { comments_template(); } } } else { theme_404_content(); } ?>When I modify it to this code below in a custom page template(to show a category of posts on a page), the menu item is not active anymore.
<?php if(have_posts()) { /* Start the Loop */ query_posts('cat=51'); while (have_posts()) { the_post(); get_template_part('content', 'post'); /* Display comments */ if ( theme_get_option('theme_allow_comments')) { comments_template(); } } } ?>Is there something I can add to the custom page template or to the loop above to get the page menu item to remain active?
thanks,
John
-
I forgot to mention that using the edited loop removes the class=”active” from the Menu ul & li, see image.
thanks,
Hey man i had the same problem a couple of minutes ago.
It should work as follows:
<?php if(have_posts()) { /* Start the Loop */ query_posts('cat=51'); while (have_posts()) { the_post(); get_template_part('content', 'post'); /* Display comments */ if ( theme_get_option('theme_allow_comments')) { comments_template(); } } } // go backwards to the original post for the custom menu wp_reset_query(); if(have_posts()) : the_post(); endif; ?>thejaeck,
Thank you! That works perfectly, I appreciate you posting this.John
Maybe this question should be in another post. I’m using the code above which pulls the Page content and list of posts and want to have the nice pagination from pageNavi plugin at the bottom for the posts.
http://wordpress.org/extend/plugins/wp-pagenavi/
How could I add that so it shows just archive/older posts for category id=51?
Thoughts? thanks.
The topic ‘loop causes page menu to not be active’ is closed to new replies.