How do I display post titles from current category and highlight active post
-
I’ve been trying to make a sidebar nav that would only display post titles from the current category you are viewing and highlight the current active post (using CSS).
I have two code snippets and would need to merge them somehow. I don’t know PHP well enough to do this myself.
Show Posts (all categories), and highlight current one using CSS:
<ul class="sidebar-ul"> <?php $IDOutsideLoop = $post->ID; global $post; $myposts = get_posts('showposts=5'); foreach($myposts as $post) : ?> <li <?php if(is_single() && $IDOutsideLoop == $post->ID) {echo " class=\"test\"";}?>><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>
Show Posts By Current Category only:
<ul> <?php while(have_posts()) : the_post(); ?> <?php foreach((get_the_category()) as $category) { $my_query = new WP_Query('category_name=' . $category->category_nicename . '&orderby=title&order=asc&showposts=100');} ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> <?php break; endwhile; ?> </ul>
Viewing 14 replies - 1 through 14 (of 14 total)
Viewing 14 replies - 1 through 14 (of 14 total)
- The topic ‘How do I display post titles from current category and highlight active post’ is closed to new replies.