我正在使用WP为一家杂志建立一个网站,我需要一次显示一个月的帖子。
How would I make the next_posts_link(); and previous_posts_link(); functions return results, shorted as one month per page?
如果我不能通过这些功能完成,我将如何以类似存档的模式显示首页?谢谢
我正在使用WP为一家杂志建立一个网站,我需要一次显示一个月的帖子。
How would I make the next_posts_link(); and previous_posts_link(); functions return results, shorted as one month per page?
如果我不能通过这些功能完成,我将如何以类似存档的模式显示首页?谢谢
您必须修改选择要按月选择的帖子的查询。放置在模板中的这段代码将获得页码,并从当前月份中减去页码。
<?php
$page = get_query_var(\'paged\') ? get_query_var(\'paged\') : 1;
$subtractor = $page-1;
$date = date("Y-m-d H:i:s");
$current_month = date(\'n\', strtotime($date.\'-\'.$subtractor.\'months\'));
$current_year = date(\'Y\', strtotime($date.\'-\'.$subtractor.\'months\'));
query_posts("monthnum=$current_month&year=$current_year&order=DESC");
if (have_posts()) :
while (have_posts()) : the_post(); // rest of the loop below
最终,这可能是最好的连接到pre\\u get\\u帖子中,以将其排除在模板之外。您还必须创建自己的分页链接,例如:
<?php
if($page>1)
echo \'<a href="/page/\'.($page-1).\'/">next</a>\';
echo \'<a href="/page/\'.($page+1).\'/">prev</a>\';
当然,你必须弄清楚帖子的发布时间,才能知道何时停止提供上个月的链接,嗯。。。我不确定这是否是你想要的;然而,这可能会有所帮助。
<?php
foreach (get_the_category() as $cat) {
$arch_date_id = $cat->cat_ID;
}
global $post;
$query = \'numberposts=-1&category=\' . $arch_date_id . \'&orderby=date&order=DESC\';
$myposts = get_posts();
foreach($myposts as $post) {
$year = get_the_time(\'Y\');
$groups[] = $year;
}
$groups = array_values(array_unique($groups));
$qi = $groups[0];
$query = \'cat=\' . $arch_date_id . \'&year=\' . $qi . \'&orderby=date&order=DESC&posts_per_page=-1\';
query_posts($query);
echo \'<h3>\' . $qi . \'</h3>\';
while (have_posts()) : the_post();
?>
<? the_date(\'F j\',\'<h3>\',\'</h3>\');?>
<? the_title();?><br />
<? endwhile; ?>
我使用CMS压力机定制帖子类型。问题是,由于lastBuildDate为空,因此无法验证源。我没有使用WordPress的默认帖子,这就是问题的根源。我用WordPress的默认帖子做了一个测试帖子,然后填写了lastBuildDate并验证了提要。我一删除帖子,它就删除了lastBuildDate中的日期,并且提要没有验证。我使用下面的代码在主提要中添加自定义帖子类型,但这也是自定义帖子类型创建的提要的问题。我是否遗漏了要填充的最后构建日期?if ( ( is_front_page() &&am