dynamic menu created with query_post of a single category
-
I have posts that, of a single category,that I wish to use for a sub navigation when viewing one of those post. Which the code below works. However, I wish to style the links with css class current_item or page_item. current_item being for the current post being view and the opposite for the other post links. Another problem that I noticed, is when my only other category {1} is being view as a single page, it still generates the links. Not really that big of a problem. I have the following code placed in my single.php file.
‘<?php $cat_posts = new WP_Query(“cat=3”); ?>
<div id=”subnav”>
<ul class=”subnav”>
<?php if($cat_posts->have_posts()) : ?><?php while($cat_posts->have_posts()) : $cat_posts->the_post(); ?><li class=”<?php if (is_single()) { ?>current_item<?php } else { ?>page_item<?php } ?>”>/<?php echo $post->post_name; ?>/” title=”<?php the_title(); ?>”><?php the_title(); ?>
<?php endwhile; ?>
<?php endif; ?>
</div><?php wp_reset_query(); ?>`
Which returns all links as current_itemI tried also tried the plain
‘<?php query_posts(“cat=3,-1”);’
to remove this sub navigation from category one.I really want to stay away from hand coding the links and plugins, If there is an easier way, please let me know. Thanks in advance for any help!
- The topic ‘dynamic menu created with query_post of a single category’ is closed to new replies.