WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] In sidebar list all posts in this post’s category

[Resolved] In sidebar list all posts in this post’s category

  • Hi

    In my header I have a horizonal bar listing categories.

    In my sidebar I list all posts in the selected category.

    This works fine when I’m on a category page but when I go to a single post page, only that post is listed in the sidebar.

    I would like some way of listing all the posts that belong to the current post’s category in the sidebar.

    Posts will only ever be in one category.

    Any help would be much appreciated.

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Paste your sidebar code to http://wordpress.pastebin.ca and post back the url.

    Thanks Moshu – here it is

    http://wordpress.pastebin.ca/993383

    THat seems to be the same as the main loop in your whatever template is used (index or archive) and it will not work: the two Loops interfere.

    I’d suggest to read about using multiple loops.

    Hi Moshu

    I haven’t changed the code from what it was in the original template. I was just wondering whether it was technically possible or whether there was a widget or plugin. I’ll read the information you suggested.

    Many thanks

    It is possible, of course.

    I haven’t changed the code from what it was in the original template.

    That’s exactly the problem.
    When the template (archive.php or category.php, whichever you have) is showing XY number of posts… your sidebar just replicates that.
    When the single.php is showing only ONE post… your sidebar again replicates it, since it is using exactly the same Loop.

    This is the reason I suggested to read about using multiple Loops.

    Many thanks again moshu. This is fixed now. Here’s my code if anyone else wants to do the same thing:

    <h3>Posts</h3>
    		<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>

    Many thanks holney this solve my problem 😀
    one thing though.. how can I exclude the active post?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] In sidebar list all posts in this post’s category’ is closed to new replies.
Skip to toolbar