• Hello everyone,
    I use the code from this wordpress forum link.
    It populate all post in years. Great! But I need to exclude the current year (it means from 2013 to oldest).

    Need an advance,
    thanks.
    Milo

    the code from the link are these:
    in functions.php:

    function posts_by_year() {
      // array to use for results
      $years = array();
    
      // get posts from WP
      $posts = get_posts(array(
        'numberposts' => -1,
        'orderby' => 'post_date',
        'order' => 'ASC',
        'post_type' => 'post',
        'post_status' => 'publish'
      ));
    
      // loop through posts, populating $years arrays
      foreach($posts as $post) {
        $years[date('Y', strtotime($post->post_date))][] = $post;
      }
    
      // reverse sort by year
      krsort($years);
    
      return $years;
    }

    in template:

    <?php foreach(posts_by_year() as $year => $posts) : ?>
      <h2><?php echo $year; ?></h2>
    
      <ul>
        <?php foreach($posts as $post) : setup_postdata($post); ?>
          <li>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
          </li>
        <?php endforeach; ?>
      </ul>
    <?php endforeach; ?>

    thanks

Viewing 1 replies (of 1 total)
  • Thread Starter designtrial

    (@designtrial)

    hello, or maybe anybody knows how to exclude category in very top of that code that i mentioned above..

    many thanks

Viewing 1 replies (of 1 total)
  • The topic ‘how to exclude current year (2014) in archive.php ?’ is closed to new replies.