我需要在我的博客页面中创建一个分页器,直到这很好,但是当我单击分页的链接时,我得到了未找到页面,我需要知道我是否需要在面板中启用某些内容来wordpress能够访问?page=N
功能:
function get_pagination($the_query) {
global $paged;
$total_pages = $the_query->max_num_pages;
$big = 999999999;
if ($total_pages > 1) {
ob_start();
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '/page/%#%',
'current' => $paged,
'total' => $total_pages,
'prev_text' => '',
'next_text' => ''
));
return ob_get_clean();
}
return null;
}
我的博客代码
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
// echo $paged;
$produtos = new WP_Query(array(
'post_type' => 'blog',
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'asc',
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'categorias',
'field' => 'slug',
'terms' => ACTIVE
)
)
));
while ( $produtos->have_posts() ) : $produtos->the_post();
//CONTENT
endwhile;
echo get_pagination($produtos);
转到管理员仪表板,然后Settings->Reading
然后设置Blog pages show at most
等于您的查询posts_per_page
。因此,在您的查询中,如果您设置了posts_per_page => 2
那么Blog pages show at most
将被2
这就是我发现并解决了我遇到的问题!
[...]我需要进入wp-admin页面(wordpress仪表板) 并转到"设置",然后转到"阅读",然后在"博客页面最多显示" 字段 I 将值从"10"更改为"6"(帖子数 I 指示在
$wp_query->query('showposts=6&cat=1'.'&paged='.$paged);
)
使用以下分页查询
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }
$produtos = new WP_Query(array(
'post_type' => 'blog',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'asc',
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'categorias',
'field' => 'slug',
'terms' => ACTIVE
)
)
));
while ( $produtos->have_posts() ) : $produtos->the_post();
//CONTENT
endwhile;
echo get_pagination($produtos);
请检查您的 .htaccess 文件。它应包含重写规则以启用带斜杠的分页。
请看:"使用漂亮的永久链接" - http://codex.wordpress.org/Using_Permalinks
Problem: When we click on next page then wordpress redirects on first
------- page or on same pag.
Solution: put this code snippet in your themes functions.php file.
--------
add_filter('redirect_canonical', 'pif_disable_redirect_canonical');
function pif_disable_redirect_canonical($redirect_url)
{
if (is_singular()) $redirect_url = false;
return $redirect_url;
}
---------------------------------------------------
! it has worked for me , I hope it works for you
转到您的 wordpress 仪表板设置,然后转到阅读,并在"博客页面最多显示"字段中,将值从"10"更改为"1"干杯!