WordPress.org

Ready to get started?Download WordPress

Forums

Post sidebar listing by category (5 posts)

  1. durannarud
    Member
    Posted 2 years ago #

    Hi,

    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?

    Thanks.

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Have you created a child theme already?

  3. durannarud
    Member
    Posted 2 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 2 years ago #

  5. durannarud
    Member
    Posted 2 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:

    <ul>
    <?php
    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; ?>
    </ul>

    Problem:

    '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