Support » Fixing WordPress » Displaying a “Post of the Day” on index.php

  • I am brainstorming a way to place a div above my content that would contain an “Article of the Day” based on the following criteria:

    The article would be shown from a specific category and it would be the most recent article in that category.

    If I miss a daily update, no big deal, the most recent post from that category will be displayed in the section.

    Is this a simple thing to do outside of the loop?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Seems like this should be pretty simple.

    Use a plugin like WP-Recent-Posts or similar (thats 2.3 compatible) and call it with a template tag. Template tags for the most part (in my experience) will work just dandy outside the loop. Set the plugin for the cat you want and to pull the most recent post.

    Then its just a matter of setting up your div in the header. If you only say wanted it on the home page you could do that with a conditional IF ishome statement.

    Hope this helps.

    You can easily create a new post loop for displaying the latest post from a specific article (modify cat=10 to the correct category ID 3 for your ‘Article of the Day’ category):

    $aotd = new WP_Query('showposts=1&cat=10');
    if( $aotd->post ) : $aotd->the_post();
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>
    <?php endif; ?>

    (The above might be called a pseudo-loop; with just one being collected there’s no reason to loop through the posts.)


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Displaying a “Post of the Day” on index.php’ is closed to new replies.