[英]Wordpress Pagination - can't access to second page
我在网站上使用WP Beginner分页(不带插件),但无法访问第二页和其他页面。
<?php
$category = get_category( get_query_var( 'cat' ) );
$cat_id = $category->cat_ID;
$custom_query_args = array(
'post_type' => array( 'tutorials','post' ),
'posts_per_page' => 2,
'cat' => $cat_id,
);
// Get current page and append to custom query parameters array
$custom_query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
// Instantiate custom query
$custom_query = new WP_Query( $custom_query_args );
// Pagination fix
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $custom_query;
// Output custom query loop
if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts() ) :
$custom_query->the_post();
echo '<article class="other-post col-xs-12 col-sm-12 col-md-3 col-lg-3">';
echo '<div class="back-color">';
echo '<h3>';
echo the_post_thumbnail('post-thumbnail', array( 'class' => 'post-image' ));
echo '<a href="'. get_permalink() .'" title="'. get_the_title() .'">';
echo '<span><b>'. get_the_title() .'</b></span>';
echo '</a>';
echo '</h3>';
echo '</div>';
echo '</article>';
endwhile;
endif;
// Reset postdata
wp_reset_postdata();
// Custom query loop pagination
wpbeginner_numeric_posts_nav();
// Reset main query object
$wp_query = NULL;
$wp_query = $temp_query;
?>
这是来自function.php的代码,但我认为这不是问题。 http://virtual-wizard.eu/function.txt
您在查询参数中缺少paged
参数。
我还将替换页面查询,所以代替这个:
// Get current page and append to custom query parameters array
$custom_query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
你有这个:
// Get current page and append to custom query parameters array
if ( get_query_var( 'paged' ) ) {
$paged = get_query_var( 'paged' );
} elseif ( get_query_var( 'page' ) ) {
$paged = get_query_var( 'page' );
} else {
$paged = 1;
}
然后将查询更改为此:
$custom_query_args = array(
'post_type' => array( 'tutorials','post' ),
'posts_per_page' => 2,
'cat' => $cat_id,
'paged' => $paged,
);
希望对您有所帮助。
尝试改用此代码。 请务必通读,因为他们正在解释如何在您的WP网站中实现此功能。
http://www.kriesi.at/archives/how-to-build-a-wordpress-post-pagination-without-plugin
函数是在functions.php内设置的,并且在想要显示分页的特定页面上,只需调用诸如pagination()之类的函数即可;
在调用分页之前,还要检查分页的CSS部分和结构以获得所需的效果。
斯雷克诺!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.