[英]Pagination not working on Post name permalink but working on plain permalink
[英]Wordpress pagination not working in home page with Post name Permalink
編輯 :即使在將“永久鏈接設置”設置為“帖子”名稱后, http://domain.com/?paged=3
仍然有效。
我在主頁上有分頁的帖子集。 假設我有
domain.com
如果我的永久鏈接設置為默認設置,例如
http://domain.com/?p=123
然后我的分頁http://domain.com/?paged=3
將起作用。
如果我希望我的永久鏈接設置采用郵政名稱格式,例如
http://domain.com/sample-post/
然后,我在主頁上的分頁將不再起作用。 如果在帖子名稱永久鏈接中設置了分頁的鏈接,我嘗試了檢查元素
http://domain.com/page/23/
然后發生的事情是它將不會轉到第23頁。它將始終重定向到我的主頁
http://domain.com
我已經嘗試過了
我把這段代碼放在我的functions.php
add_filter( 'redirect_canonical','custom_disable_redirect_canonical' );
function custom_disable_redirect_canonical( $redirect_url ){
if ( is_singular('your_custom_post_type') ) $redirect_url = false;
return $redirect_url;
}
而且它沒有用。
更新我檢查了functions.php
,我看到了
/* -----------------------------------------------------------------------------
Woo commerce
*/
if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' )))) { // check if we have woo commerce installed
// breadcrumb
add_filter( 'woocommerce_breadcrumb_defaults', 'td_woocommerce_breadcrumbs' );
function td_woocommerce_breadcrumbs() {
return array(
'delimiter' => ' <span class="td-sp td-sp-breadcrumb-arrow td-bread-sep"></span> ',
'wrap_before' => '<div class="entry-crumbs" itemprop="breadcrumb">',
'wrap_after' => '</div>',
'before' => '',
'after' => '',
'home' => _x( 'Home', 'breadcrumb', 'woocommerce' ),
);
}
// number of products to display on shop page
add_filter('loop_shop_per_page', create_function('$cols', 'return 8;'));
if (!function_exists('woocommerce_pagination')) {
// pagination
function woocommerce_pagination(){
echo td_page_generator::get_pagination();
}
}
if (!function_exists('woocommerce_output_related_products')) {
// number of related product
function woocommerce_output_related_products() {
woocommerce_related_products(4,4); // Display 4 products in rows of 4
}
}
}
/**
* Add prev and next links to a numbered link list - the pagination on single.
*/
function wp_link_pages_args_prevnext_add($args)
{
global $page, $numpages, $more, $pagenow;
if (!$args['next_or_number'] == 'next_and_number')
return $args; # exit early
$args['next_or_number'] = 'number'; # keep numbering for the main part
if (!$more)
return $args; # exit early
if($page-1) # there is a previous page
$args['before'] .= _wp_link_page($page-1)
. $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>'
;
if ($page<$numpages) # there is a next page
$args['after'] = _wp_link_page($page+1)
. $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
. $args['after']
;
return $args;
}
add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');
add_theme_support('woocommerce');
它沒有woo Commerce插件,但是有該代碼。 希望它可以幫助您了解發生了什么事情?
如果您使用WP_Query檢索帖子,則將代碼更改為以下內容
$paged = ( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
$args = array(
'posts_per_page' => 5,
'post_type' => 'post',
'paged' => $paged,
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post();
the_title();
echo '<br>';
endwhile;
$big = 999999999;
echo paginate_links( array(
'format' => '?paged=%#%',
'current' => max( 1, $paged ),
'total' => $the_query->max_num_pages
) );
除了上述提到的方案之外,請確保您沒有正在使用循環的模板的錯誤,類似於主題中存在的任何帖子類型。 如果頁面信息與帖子類型信息相似,則分頁將無法正常工作。
page name
和custom post type
使用相同的名稱。 如果這樣做,頁面名稱的頁面url-slug和自定義帖子類型的slug相同,將導致未找到錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.