WordPress.org

Ready to get started?Download WordPress

Forums

Need how-to assistance for displaying specific posts (5 posts)

  1. dmahler
    Member
    Posted 7 months ago #

    I know I'm probably missing the obvious and I did a search on here to find the answer but I'm getting no where fast.

    I need the home page to always show the most recent blog post under the "comic" category followed by the most recent blog post under the "blog" category on this site:
    http://laughingiron.com/

    Right now, they are reversed.

    How do I hard code that either on the page or on some php page?

    I've been trying to find the answer for weeks now and figured I'd get some expert help here.

    We are using WordPress 3.6.

    Any help would be deeply appreciated!

  2. Evan Herman
    Member
    Posted 7 months ago #

    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

  3. dmahler
    Member
    Posted 7 months ago #

    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!

  4. Evan Herman
    Member
    Posted 7 months ago #

    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

  5. dmahler
    Member
    Posted 7 months ago #

    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!

Reply

You must log in to post.

About this Topic