Forums

[resolved] query-posts to display only one category on main page (6 posts)

  1. bornfamous
    Member
    Posted 4 years ago #

    I'm having trouble following the instructions here:

    http://codex.wordpress.org/Template_Tags/query_posts

    I want just one category to show up on my front page but I can't figure out where to put the query_posts tag. I tried putting it before the Loop, as stated in the instructions, but that didn't work.

    Any suggestions?

    TIA

  2. moshu
    Member
    Posted 4 years ago #

    Well, everything is there - but if you cannot make it work for you, this http://wordpress.org/support/topic/49006#post-269672 was just posted recenly as an alternate solution.

  3. bornfamous
    Member
    Posted 4 years ago #

    Here's where I put the query_posts tag, but it doesn't work:

    <?php query_posts('cat=1'); ?>
    <?php if ($posts) { ?>
    <?php foreach ($posts as $post) : start_wp(); ?>
    <?php require('post.php');?>
    <?php endforeach; ?>

  4. bornfamous
    Member
    Posted 4 years ago #

    Can anyone spot what I did wrong in the code above?

  5. igorboog
    Member
    Posted 4 years ago #

    I use the following (in my not yet visible site in development).

    When I only want to show category 2:
    $wp_query->set('cat', '2');
    query_posts('');

    And then the loop starts:
    if (have_posts()) : while (have_posts()) : the_post();

    And so on. Note: this will display posts that are in cat 2, but also posts that are also in cat 2.

  6. bornfamous
    Member
    Posted 4 years ago #

    It worked! Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic