如果可能的话,如何获取前一周帖子的RSS提要?
我从@Bainternet找到了一个解决方案(参见1, 2), 但我不知道如何在我的情况下实施它。
现在我可以显示前一周的帖子(参见下面的代码,改编自wpbeginner.com), 但我也需要一个feed链接。
// Display previous week’s posts
add_shortcode(\'lastweek\', \'wpb_last_week_posts\');
function wpb_last_week_posts() {
ob_start();
$thisweek = date(\'W\');
if ($thisweek != 1) :
$lastweek = $thisweek - 1;
else :
$lastweek = 52;
endif;
$year = date(\'Y\');
if ($lastweek != 52) :
$year = date(\'Y\');
else:
$year = date(\'Y\') -1;
endif;
$the_query = new WP_Query( \'year=\' . $year . \'&w=\' . $lastweek . \'posts_per_page=5\' );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?> "><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<!-- Display recent posts if no posts in the previous week -->
<ul><?php $the_query = new WP_Query( \'posts_per_page=5\' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php the_excerpt(); ?>
<?php endwhile;
wp_reset_postdata();
?>
</ul>
<?php endif;
$output = ob_get_contents();
ob_end_clean();
return $output;
}