WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Change Loop to Show Recent Posts Only from 1 Category (3 posts)

  1. Aaress
    Member
    Posted 1 year ago #

    Hi,

    I'm using a custom widget to display a listing of recent posts.

    However, I'd like to only show the posts from a particular category, offset by one, as that story will be featured in the slider above the widget.

    Here is my current query code (for this one I'd like to pick the category with the offset):

    <?php $recent = new WP_Query('showposts=' . $post_num . ' '); while($recent->have_posts()) : $recent->the_post();?>

    Also, I'd like to offset it by one here as well, but the category calls are already in place:

    <?php $recent = new WP_Query(array( 'category_name' => ' ' . $category2 . ' ', 'showposts' => '1'  )); while($recent->have_posts()) : $recent->the_post();?>

    Thanks for the help!

  2. Steven Jones
    Member
    Posted 1 year ago #

    Just using the real values instead of variables, this is what you need.

    $recent = new WP_Query('showposts=5&offset=1&cat=4');

    So that's showing the posts 2-6 from category 4.

  3. Aaress
    Member
    Posted 1 year ago #

    Hi Steven,

    Thanks for the help! I used that and it worked great! I appreciate it!

Topic Closed

This topic has been closed to new replies.

About this Topic