WordPress.org

Support

Support » How-To and Troubleshooting » Need how-to assistance for displaying specific posts

Need how-to assistance for displaying specific posts

Viewing 4 replies - 1 through 4 (of 4 total)
  • Something like this should suffice

    <?php query_posts('cat=5'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <?php the_content(); ?>
    <?php endwhile; endif; ?>

    ‘cat=5’ refers to Category 5, where 5 is the ID of the specific category you are targeting. To get thet ID of the category you want to target, go to your admin dashboard and do the following

    1. Posts > Categories

    2. Select the category you would like to target

    3. Check the URL Bar, you should see something like this:
    http://websiteaddress.com/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=42&post_type=post

    Notice ‘Category&tag_ID=42’ in the URL. This is what shows you the ID for the category you have just selected.

    Now input that number in to the query post loop and it will pull and display all posts from that category

    Thank you so much!
    2 Quick final questions Evan.

    What if I only want 1 post from each category?

    And where do I put this? On the home page .php? Or can I put that in the text editor?

    Thank you again!

    If you want to limit it to one post you can set a post_per_page limit on the query by adding this:

    <?php query_posts('cat=5&post_per_page=1'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <?php the_content(); ?>
    <?php endwhile; endif; ?>

    You can add it to your index.php or whatever the homepage php file is for your site

    OMG Evan! You are a lifesaver! Is there some where I can make a donation to you for your expert help?

    You have no idea how much this helped me!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Need how-to assistance for displaying specific posts’ is closed to new replies.