WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display only posts from one category on homepage (11 posts)

  1. databell96
    Member
    Posted 5 years ago #

    I'm trying to figure out how on the homepage I can only display the posts from just one category instead of several categories. I figured out how to display content from a page, but I want to display posts. Just from one category.

  2. MichaelH
    Member
    Posted 5 years ago #

    Use the template tag, query_posts(), and the cat= parameter.

    Resources:
    The Loop
    Template Hierarchy
    Stepping Into Templates

  3. databell96
    Member
    Posted 5 years ago #

    I tried that in a home.php template and it just came up with a Parse Error on line 44. Did I place the content correctly?

    [code moderated]

  4. MichaelH
    Member
    Posted 5 years ago #

    See if this works:
    http://pastebin.ca/1222663

  5. databell96
    Member
    Posted 5 years ago #

    Still get this:
    Parse error: parse error, unexpected T_ENDWHILE in /home/content/w/i/l/willdurst/html/lobsterssundaybrunch/wp-content/themes/lsb/home.php on line 44

  6. MichaelH
    Member
    Posted 5 years ago #

    Oops, missed the extra endif and endwhile

    http://pastebin.ca/1222698

  7. databell96
    Member
    Posted 5 years ago #

    Yep, that did the trick. Thanks so much for your help.

  8. henriquecruz
    Member
    Posted 5 years ago #

    Hi MichaelH, could you post that code again? I believe your post on pastebin has expired...!

  9. sshilo
    Member
    Posted 5 years ago #

    yes, please, someone re-post that code.

  10. alexjones
    Member
    Posted 5 years ago #

    I used this <?php query_posts('cat=1&amp;showposts='.get_option('posts_per_page')); ?> before the loop, you need to change cat=1 to the id of your category.
    I would like to achieve something else, show posts only from one category but the latest post from that category to be styled different.`
    What I have now does this thing, styles different the latest post only if the post is from that category, if the latest post is from another category I see regular posts.

    Any ideas?

  11. TylorFamous
    Member
    Posted 4 years ago #

    Thanks! That's exactly what I was looking for.

Topic Closed

This topic has been closed to new replies.

About this Topic