• I’m trying to set up a sidebar with a list of posts from a single category. This is outside The Loop. But I can’t seem to get much info from the Codex on this subject.

    It would seem that some form of get_posts should do it, but I haven’t been able to make it work (there are no helpful examples on the get_posts Codex page…)

    So, what I’d like to do is put up a simple list, with </li> <li> separators, for a certain number of posts (say, 7), in a certain category (say, 57). Can anyone help me out? Do I have to set it up inside a Query or in some sort of second Loop?

    All I know right now is that this doesn’t seem to do anything:

    <ul class="onecatposts">
        <?php get_posts('&category_in=57'); >
    </ul>

    Thanks in advance for any advice.

Viewing 3 replies - 1 through 3 (of 3 total)
  • This is what I use which works perfectly fine. Obviously change ‘XYZ’ to whatever number category you want

    <?php query_posts('showposts=6&cat=XYZ'); ?>
    <ul>
    
     	<?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
     	<?php endwhile; ?>
    </ul>
    Thread Starter bugreporter123

    (@bugreporter123)

    Just one Q: Is 6 the limit of the # of posts shown?

    I will try this, thanks.

    Thread Starter bugreporter123

    (@bugreporter123)

    OK, I had to add a

    <?php wp_reset_query(); ?>

    at the end of it, so the main Loop wasn’t affected, but then it worked just great!

    Thanks, this saved me HOURS of digging through the Codex. Mark this one as “resolved”!

    ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do I create a list of one category’s posts in a sidebar?’ is closed to new replies.