Let's say I have a post called "Hello World" and I am on that page... Let's say I have different posts like "Haaaa" and "Hoooo".... What I want to do is showing Haaa and Hooo in a different place (let us say the sidebar) if this "Hello World" post is being watched...

So in the sidebar we get this:

<div class="highlighted active"> Hello World </div>

Where do I start? I guess <?php wp_get_archives('type=alpha'); ?>, but how do I get what I want?


For the solution you can use if statement as below
put it in your sidebar, it will highlight the current post title.

$IDOutsideLoop = $post->ID;
$args = array( 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC' );
$myposts = get_posts( $args );
foreach($myposts as $post) :
<li <?php if(is_single() && $IDOutsideLoop == $post->ID) print 'style="font-weight:bold";' ?>><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>

Even wordpress provides for highlighting the current pages here,
it doesn't include to hightlight the specific post's title at sidebar.

I don't know if you are looking for static navigation , the below link might help you .

  • How does this do it in an alphabetic order? Highlighting the current post isn't a problem (I guess, haven't looked on that one), but outputting 5 posts alphabetically before and after the current post is a big problem... I guess this does not do the thing I want. – user1627363 May 14 '13 at 9:30
  • I re-changed the codes as an array 'oder' => 'ASC' . hope it work for you. – Ronald May 14 '13 at 9:42
  • Thanks, but it does not do what I want. Let's say you are on single.php and you clicked a post called "Hello"... What I want it to do is that it outputs the 5 posts that are alphabetically before the post and 5 posts that are after the post (also alphabetically)... I appreciate your help, but it doesn't solve this problem. – user1627363 May 17 '13 at 9:40
  • No one who can help? – user1627363 May 23 '13 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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