关于WordPress相关文章、最新文章的调用我们应该还好办,比如默认的系统就支持调用最新文章的模块,以及相关文章我们可以使用插件或者无插件调用。但是,如果我们需要调用上一周网站更新的内容如何实现呢?因为公司某个网站需要调用上一周的内容出来,老蒋就找找看看有没有非插件实现的方法。
如果使用插件很简单,这里我不用插件,于是找到一个不错的方法。
第一、调用上一周文章代码


function wpweek_this_week() {
$week = date('W');<br> $year = date('Y');
$the_query = new WP_Query( 'year=' . $year . '&w=' . $week );<br> if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>


<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else:  ?>

<?php _e( '没有合适的内容' ); ?>


<?php endif;
}

将代码添加到当前主题的Functions.php文件中。
第二步、调用文章

<?php wpweek_this_week(); ?>

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


扫描二维码,在手机上阅读!