您似乎正在尝试对$all_work
查询数据,但分页代码正在使用$wp_query
数据
global $wp_query;
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var(\'paged\'));
。。。因为我不知道的原因。
如果要分页$all_work
您需要使用$all_work
数据中的数据$wp-query
不会是正确的。我怀疑是这种查询的混合造成了问题,我怀疑类似的查询混合也是建议的副本中的代码不适合您的原因。
像这样的方法应该会奏效:
$page = (!empty($_GET[\'myp\'])) ? $_GET[\'myp\'] : 1;
$per_page = 1;
$base = get_queried_object();
// var_dump($base);
if (null === $base) {
$base = site_url();
} else {
$base = get_permalink($base->ID);
}
// $paged = ( get_query_var(\'paged\') ) ? get_query_var(\'paged\') : 1;
$all_work = new WP_Query(array(
\'post_type\' => \'page\',
// \'tax_query\' => array(
// array(
// \'taxonomy\' => \'type\',
// \'field\' => \'slug\',
// \'terms\' => array(\'case-study\', \'portfolio\')
// ),
// ),
\'posts_per_page\' => $per_page,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'update_post_term_cache\' => false,
\'nopaging\' => false,
\'paged\' => $page
)
);
$total = $all_work->found_posts;
var_dump($total);
while ( $all_work->have_posts() ) {
$all_work->the_post();
the_title(0);
}
$page_args = array(
\'base\' => $base.\'%_%\',
\'format\' => \'?myp=%#%\',
\'total\' => ceil($total / $per_page),
\'current\' => $page,
\'show_all\' => True,
\'end_size\' => 1,
\'mid_size\' => 1,
\'prev_next\' => True,
\'prev_text\' => __(\'« Previous\'),
\'next_text\' => __(\'Next »\'),
\'type\' => \'plain\',
);
echo \'<br/>\';
echo paginate_links($page_args);
这是通用代码,因为我的服务器上没有您的数据,但很明显需要更改什么。