Post sidebar listing by category (5 posts)

  1. durannarud
    Posted 3 years ago #


    On my post pages (working with twentyeleven), I'd like to have a sidebar that displays a list of the latest posts in the category to which the posts in question belongs to (as opposed to latest posts on the entire site, for instance).

    How do I go about doing this? Or is there maybe a tutorial regarding this specific part of the site and how to edit it?


  2. esmi
    Forum Moderator
    Posted 3 years ago #

    Have you created a child theme already?

  3. durannarud
    Posted 3 years ago #

    That was the original plan, but I decided to just make a copy of the theme folder and edit it directly instead. I was reading that if you're making too many changes, you may as well do that instead of a child theme. So yeah, nothing to bypass...

  4. esmi
    Forum Moderator
    Posted 3 years ago #

  5. durannarud
    Posted 3 years ago #

    Thanks. From what I gather:

    Make a sidebar for the post pages: http://voodoopress.com/adding-a-narrow-sidebar-on-each-side-of-twentyeleven-single-post-view/

    Insert category titles into said sidebar:

    global $post;
    $args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>


    'category' => 1

    What code should I replace this with in order to tell it to pick the category of the post itself rather than a category indicated by me?

Topic Closed

This topic has been closed to new replies.

About this Topic