关于WordPress相关文章、最新文章的调用我们应该还好办,比如默认的系统就支持调用最新文章的模块,以及相关文章我们可以使用插件或者无插件调用。但是,如果我们需要调用上一周网站更新的内容如何实现呢?因为公司某个网站需要调用上一周的内容出来,– 2 + o ^ B ] t我们就找找看看有没有非插件实现的方法# ^ z F [ o 6。
如果使用插件很简单,} { J Q这里我不用插件,于是找到一个不错的方法。
第一、调用上一周文章代码
- functionwpweek_this= ) b # o L_weekx G c(){
- $week=date(‘l x 1 k % p UW’);
- $yV , f Y uear=date(‘Y’);
- $the_query=newWP_Query(‘year=’.$year.‘&w=’.$week);
- if($the_query->have_posts()):
- while($the_query->have_posts()):$C 7 ]the_query->b % S M \the_post();?– s g r 5 ~ Y #>
- <h2><ahref=“<?phpthe_permalink();?>”title=“<?phpthe_titlE R Y * 7 $e();?>“><?v [ ) 4 | +phpthe_tO z B ! # y uitle();?></a></h2>
- <?phpthe_excerpt();?>
- <?phpendwhile;?>
- <?phpwp_reset_postdata();?>
- <?phpelH l M ^ d 0 ; 1se:?>S _ & Z l M [ l 9
- <p><?php_e(‘没有合适的i I o l C U内容’);?></p>
- <?phpendif;
- }
将` ] 1 $ h f M l代– n S码添加到当前主题的Functions.php文件中。
第二步、调用文章
- <?phpwpwS q { : A 0 D meek_this_week();?>
然后在需要调用的位置,输入上面代码就可以。
特别声明:本站所收录作品、热点评论等信息来源互联网,目的只是为了系统归纳学习和传递资讯所有作品版权归原创作者所有,与本站立场无关,图文源自网络,如有侵权,请联系删除!请联系我们邮箱:908164873@qq.com/电话:187-8421-3206,我们将做删除处理!