WordPress.org

Forums

How can I get last post of specific category? (4 posts)

  1. evergreen
    Member
    Posted 10 years ago #

    Hi,

    On a new site I am making, I want to take the last post in say category named "News" and place it aside from normal posts.

    How might this be accomplished?

    Thanks

  2. Joshua Sigar
    Member
    Posted 10 years ago #

    Say category "News" has category id of 1.

    <?php $posts = get_posts( "category=1&numberposts=3″ ); ?>
    <?php if( $posts ) : ?>

    <div class="section" id="latestNews">
    <h2>Latest News</h2>
    <ul>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>

    <li><span class="date"><?php the_time('F j'); ?></span> <a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>

    <?php endforeach; ?>
    </ul>
    </div>

    <?php endif; ?>

  3. evergreen
    Member
    Posted 10 years ago #

    Ah thanks. I will try that out. :D

  4. moshu
    Member
    Posted 10 years ago #

    Last year I have asked a similar question and got a solution from Kafkaesqui:
    http://wordpress.org/support/topic/28203?replies=11#post-193667
    You can see it in action by clicking on my name here.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags