按年过滤(wordpress)

时间:2017-06-05 12:06:41

标签: php wordpress date filtering

我想按年过滤新闻。

对于前。 | 2017 | 2016 | 2015 | 2014 |

点击日期后,它会显示所选年份的所有帖子。

我尝试使用此源代码:

<?php
query_posts(array('nopaging' => 1, ));
$prev_year = null;
if ( have_posts() ) {
   while ( have_posts() ) {
      the_post();
      $this_year = get_the_date('Y');
      if ($prev_year != $this_year) {
          if (!is_null($prev_year)) {
             echo '</ul>';
          }
          echo '<h3>' . $this_year . '</h3>';
          echo '<ul>';
      }
      echo '<li>';
      echo '</li>';
      $prev_year = $this_year;
   }
   echo '</ul>';
}
  ?>

我在链接到年份方面存在问题;如何添加href属性来链接岁月?

0 个答案:

没有答案