WordPress.org

Ready to get started?Download WordPress

Forums

Daily Archive (3 posts)

  1. Jack_2010
    Member
    Posted 3 years ago #

    hi
    i read all of topics about daily archive
    but i cant create daily archive like this
    E.g.,:
    Tuesday 11 November 2010
    :: Post 2
    :: Post 1

    Sunday 9 November 2010
    :: Post 2
    :: Post 1

  2. MichaelH
    Member
    Posted 3 years ago #

    <?php
    // list all posts, sectioned by post date
    $args=array(
      'orderby' => 'date',
      'order' => 'DESC',
      'posts_per_page'=>-1,
      'caller_get_posts'=>1
    );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'Date archive of all ' . count($my_query->posts) . ' posts';
      while ($my_query->have_posts()) : $my_query->the_post();
        $this_date =  get_the_time(__('l d F Y'));
        if ($this_date != $last_date) {
          $last_date = $this_date;
          echo '<h2>'.$last_date.'</h2>';
        } ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    } //if ($my_query)
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. adkbasecamp
    Member
    Posted 3 years ago #

    Thanks for the code. I removed the display of number of posts, added display of content, and put the code into a Page Template:

    Screenshot

    Question: How do I limit the number of days displayed? i.e. the most recent 3 days.

    <?php
    // list all posts, sectioned by post date
    $args=array(
      'orderby' => 'date',
      'order' => 'DESC',
      'posts_per_page'=>-1,
      'caller_get_posts'=>1
    );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post();
        $this_date =  get_the_time(__('l d F Y'));
        if ($this_date != $last_date) {
          $last_date = $this_date;
          echo '<h2>'.$last_date.'</h2>';
        } ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br /><?php the_content(); ?></p>
        <?php
      endwhile;
    } //if ($my_query)
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.