WordPress.org

Ready to get started?Download WordPress

Forums

Show post from a specific category (2 posts)

  1. andytford
    Member
    Posted 4 years ago #

    Either I'm an idiot or haven't located exactly what I am looking for. I believe my issue is pretty simply, but I'm having no luck:

    I would like to display the 3 most recent post from my Blog category (cat=1)within the template for my homepage (home.php).

    How do I do this? And thanks in advance to anyone willing to help.

  2. MichaelH
    Member
    Posted 4 years ago #

    <?php
    //display 3 post from category 109
       $args=array(
       'showposts'=>3,
       'category__in' => array(109),
       'caller_get_posts'=>1
       );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><small><?php the_time('m.d.y') ?></small> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php
    the_content(); //use the_excerpt() for a summary
    ?>
    <?php
    //this is necessary to show the tags
    global $wp_query;
    $wp_query->in_the_loop = true;
    endwhile;
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic