关于WordPress相关文章、最新文章的调用我们应该还好办,比如默认的系统就支持调用最新文章的模块,以及相关文章我们可以使用插件或者无插件调用。但是,如果我们需要调用上一周网站更新的内容如何实现呢?因为公司某个网站需要调用上一周的内容出来,– 2 + o ^ B ] t我们就找找看看有没有非插件实现的方法# ^ z F [ o 6

如果使用插件很简单,} { J Q这里我不用插件,于是找到一个不错的方法。

第一、调用上一周文章代码

  1. functionwpweek_this= ) b # o L_weekx G c(){
  2. $week=date(‘l x 1 k % p UW’);
  3. $yV , f Y uear=date(‘Y’);
  4. $the_query=newWP_Query(‘year=’.$year.‘&w=’.$week);
  5. if($the_query->have_posts()):
  6. while($the_query->have_posts()):$C 7 ]the_query->b % S M \the_post();?– s g r 5 ~ Y #>
  7. <h2><ahref=“<?phpthe_permalink();?>”title=“<?phpthe_titlE R Y * 7 $e();?>“><?v [ ) 4 | +phpthe_tO z B ! # y uitle();?></a></h2>
  8. <?phpthe_excerpt();?>
  9. <?phpendwhile;?>
  10. <?phpwp_reset_postdata();?>
  11. <?phpelH l M ^ d 0 ; 1se:?>S _ & Z l M [ l 9
  12. <p><?php_e(‘没有合适的i I o l C U内容’);?></p>
  13. <?phpendif;
  14. }

` ] 1 $ h f M l– n S码添加到当前主题的Functions.php文件中。

第二步、调用文章

  1. <?phpwpwS q { : A 0 D meek_this_week();?>

然后在需要调用的位置,输入上面代码就可以。