WordPress.org

Ready to get started?Download WordPress

Forums

Organizing Blog Posts by Date, is it Possible? (4 posts)

  1. Caitiebs
    Member
    Posted 4 years ago #

    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!

  2. vtxyzzy
    Member
    Posted 4 years ago #

    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
       endwhile;
    else:
       // Code for no posts found
    endif;
    ?>
  3. Caitiebs
    Member
    Posted 4 years ago #

    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?

  4. vtxyzzy
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic