• 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

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?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().
    ?>

    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().
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Daily Archive’ is closed to new replies.