此循环(用于分类术语存档页)分页不正确。第2页的旧/新链接已经存在,但当我单击旧链接时,它会返回“找不到内容”(当我期望看到此存档的第二篇文章时)。我错过什么了吗?
<?php
/**
* Template for various archive pages (category, tag, term, date, etc.
*/
get_header();
?>
<div id="content" class="stories span8" role="main">
<?php if ( have_posts() ) { ?>
<?php
// queue up the first post so we know what type of archive page we\'re dealing with
the_post();
/*
* Display some different stuff in the header
* depending on what type of archive page we\'re looking at
*/
// if it\'s an author page, show the author box with their bio, social links, etc.
if ( is_author() ) {
get_template_part( \'largo-author-box\' );
// for categories, tags, and custom taxonomies we show the term name and description
} elseif ( is_category() || is_tag() || is_tax() ) {
if ( is_category() ) {
$title = single_cat_title( \'\', false );
$description = category_description();
} elseif ( is_tag() ) {
$title = single_tag_title( \'\', false );
$description = tag_description();
} elseif ( is_tax() ) {
$title = single_term_title( \'\', false );
$description = term_description();
}
?>
<header class="archive-background clearfix">
<?php
if ( $title)
echo \'<h1><img src="http://largoproject.staging.wpengine.com/wp-content/themes/maine/images/whoyakidding_logo.jpg" border=0></h1>\';
// category pages show a list of related terms
if ( is_category() && largo_get_related_topics_for_category( get_queried_object() ) != \'<ul></ul>\' ) { ?>
<div class="related-topics">
<h5><?php _e(\'Related Topics:\', \'largo\'); ?> </h5>
<?php echo largo_get_related_topics_for_category( get_queried_object() ); ?>
</div> <!-- /.related-topics -->
<?php
}
?>
<?php
// if it\'s a date archive we\'ll show the date dropdown in lieu of a description
} elseif ( is_date() ) {
?>
<nav class="archive-dropdown">
<select name="archive-dropdown" onchange=\'document.location.href=this.options[this.selectedIndex].value;\'><option value=""><?php _e(\'Select Month\', \'largo\'); ?></option>
<?php wp_get_archives( array(\'type\' => \'monthly\', \'format\' => \'option\' ) ); ?>
</select>
</nav>
<?php } ?>
</header>
<h3 class="recent-posts clearfix">
<?php
/*
* Show a label for the list of recent posts
* again, tailored to the type of page we\'re looking at
*/
$posts_term = of_get_option( \'posts_term_plural\', \'Stories\' );
if ( is_author() ) {
if ( function_exists( \'get_coauthors\' ) && $author = get_coauthors( $post->ID ) ) {
printf(__(\'Recent %1$s<a class="rss-link" href="/author/%2$s/feed/"><i class="icon-rss"></i></a>\', \'largo\'), $posts_term, $author[0]->user_login );
} else {
printf(__(\'Recent %1$s<a class="rss-link" href="%2$s"><i class="icon-rss"></i></a>\', \'largo\'), $posts_term, get_author_feed_link( get_the_author_meta(\'ID\') ) );
}
} elseif ( is_category() ) {
printf(__(\'Recent %1$s<a class="rss-link" href="%2$s"><i class="icon-rss"></i></a>\', \'largo\'), $posts_term, get_category_feed_link( get_queried_object_id() ) );
} elseif ( is_tag() ) {
printf(__(\'Recent %1$s<a class="rss-link" href="%2$s"><i class="icon-rss"></i></a>\', \'largo\'), $posts_term, get_tag_feed_link( get_queried_object_id() ) );
} elseif ( is_tax() ) {
$queried_object = get_queried_object();
$term_id = intval( $queried_object->term_id );
$tax = $queried_object->taxonomy;
printf(__(\'Recent %1$s<a class="rss-link" href="%2$s"><i class="icon-rss"></i></a>\', \'largo\'), $posts_term, get_term_feed_link( $term_id, $tax ) );
} elseif ( is_month() ) {
printf(__(\'Monthly Archives: <span>%s</span>\', \'largo\'), get_the_date(\'F Y\') );
} elseif ( is_year() ) {
printf(__(\'Yearly Archives: <span>%s</span>\', \'largo\'), get_the_date(\'Y\') );
} else {
_e(\'Archives\', \'largo\');
}
?>
</h3>
<?php
// and finally wind the posts back so we can go through the loop as usual
rewind_posts();
query_posts(\'posts_per_page=1\');
while ( have_posts() ) : the_post();
get_template_part( \'content\', \'singleseries\' );
endwhile;
largo_content_nav( \'nav-below\' );
} else {
get_template_part( \'content\', \'not-found\' );
}
?>
</div><!--#content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
SO网友:s_ha_dum
我不知道是什么largo_content_nav()
但您在此处删除了主查询:
query_posts(\'posts_per_page=1\');
然后几行之后尝试分页(或者函数名和参数建议):
largo_content_nav( \'nav-below\' );
如果
largo_content_nav
使用
global
变量
$wp_query
我想这一定是因为你没有通过
WP_Query
对象,则您将基于与用于加载页面的对象不同的对象进行分页。即:
早在加载主题模板之前,WordPress就创建了$wp_query
global
基于各种查询参数和重写规则
页面根据该查询中的信息加载,方法是使用query_posts
你不应该这样做,然后重写$wp_query
然后尝试分页。很遗憾,您在第3步更改了查询。事情不同步我真的不明白(或者我不确定我是否理解)您试图用这段代码实现什么,但是您下面的评论。。。
我所需要做的就是在这个分类术语的档案中每页显示一篇完整的文章。
。。。让我觉得你所要做的就是将存档限制为每页一个结果。页面上有两个循环,但似乎您只想要一个,并且编造了一些奇怪且极其复杂的东西。我think 您需要的是:
function single_per_page_archive_wpse_133857($qry) {
if ($qry->is_main_query() && $qry->is_archive()) {
$qry->set(\'posts_per_page\',1);
}
}
add_action(\'pre_get_posts\',\'single_per_page_archive_wpse_133857\');
并删除其中大部分:
// and finally wind the posts back so we can go through the loop as usual
rewind_posts();
query_posts(\'posts_per_page=1\');
while ( have_posts() ) : the_post();
get_template_part( \'content\', \'singleseries\' );
endwhile;
仅保留以下内容(我认为):
get_template_part( \'content\', \'singleseries\' );