Support » Fixing WordPress » Organizing Blog Posts by Date, is it Possible?

  • I am trying to cut down the clutter on my home page of my blog, and right now I can choose to display the most recent posts by number, but I was wondering if I can set it so it only shows posts that I’ve written that day?

    For example, if I wrote three posts yesterday, it would show those three posts, but if if I only wrote one post today, it would only show that one post. To see older posts the reader would have to click the archives.

    Is this possible?

    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • It is certainly possible with a bit of coding. Here is a skeleton of code that should get you started (UNTESTED):

    <?php // Show up to 3 posts from latest post date
    $latest_date = getdate(); // Default to today
    $my_query = new WP_Query('posts_per_page=1&caller_get_posts=1');
    if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
       $latest_date = getdate(strtotime($post->post_date));
    endwhile; endif;
    $args = array(
       'posts_per_page' => 3,
       'caller_get_posts' => 1,
       'year' => $latest_date['year'],
       'monthnum' => $latest_date['mon'],
       'day' => $latest_date['mday'],
    $my_query = new WP_Query($args);
    if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
       // Code to display posts
       // Code for no posts found

    Thanks for the code! Do I need to edit my css for this or can I just put it in a hidden text box as html?

    Sorry, but neither of those things is correct. It is only a skeleton and needs to be integrated into the PHP code that is used to display your home page (probably either index.php, or home.php).

    If you are using a free theme, post its name and I will take a look.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Organizing Blog Posts by Date, is it Possible?’ is closed to new replies.