您有使用wordpress创建的博客(codepedia.info)。
它工作正常,但现在面临一个问题,在 category page 分页下无法正常工作。 任何人都可以告诉我在哪里寻找下面的网址
www.domain.com/category/categoryname/page/2
www.domain.com/category/categoryname/page/3
...
是wordpress的新手,我正在使用报纸主题。 的 /includes/wp_booster/td_page_generator.php
<?php
class td_page_generator {
/**
* get the single breadcrumbs
* @param $post_title
* @return string
*/
static function get_single_breadcrumbs($post_title) {
/**
* check to see if we are on a custom post type page. If that's the case we will load the breadcrumbs
* via @see td_page_generator::get_custom_post_type_breadcrumbs() - in this file
*/
global $post;
if ($post->post_type != 'post') {
return self::get_custom_post_type_breadcrumbs();
}
// get the breadcrumb for single posts - ! if we are on a custom post type, we don't get here !
if (td_util::get_option('tds_breadcrumbs_show') == 'hide') {
return '';
}
$category_1_name = '';
$category_1_url = '';
$category_2_name = '';
$category_2_url = '';
$primary_category_id = td_global::get_primary_category_id();
$primary_category_obj = get_category($primary_category_id);
//print_r($primary_category_obj);
if (!empty($primary_category_obj)) {
if (!empty($primary_category_obj->name)) {
$category_1_name = $primary_category_obj->name;
} else {
$category_1_name = '';
}
if (!empty($primary_category_obj->cat_ID)) {
$category_1_url = get_category_link($primary_category_obj->cat_ID);
}
if (!empty($primary_category_obj->parent) and $primary_category_obj->parent != 0) {
$parent_category_obj = get_category($primary_category_obj->parent);
if (!empty($parent_category_obj)) {
$category_2_name = $parent_category_obj->name;
$category_2_url = get_category_link($parent_category_obj->cat_ID);
}
}
}
if (!empty($category_1_name)) {
//parent category (only if we have one and if the theme is set to show it)
if (!empty($category_2_name) and td_util::get_option('tds_breadcrumbs_show_parent') != 'hide' ) {
$breadcrumbs_array [] = array (
'title_attribute' => __td('View all posts in', TD_THEME_NAME) . ' ' . htmlspecialchars($category_2_name),
'url' => $category_2_url,
'display_name' => $category_2_name
);
}
//child category
$breadcrumbs_array [] = array (
'title_attribute' => __td('View all posts in', TD_THEME_NAME) . ' ' . htmlspecialchars($category_1_name),
'url' => $category_1_url,
'display_name' => $category_1_name
);
//article title (only if the theme is set to show it)
if (td_util::get_option('tds_breadcrumbs_show_article') != 'hide') {
//child category
$breadcrumbs_array [] = array (
'title_attribute' => $post_title,
'url' => '',
'display_name' => td_util::excerpt($post_title, 13)
);
}
}
if (isset($breadcrumbs_array) and is_array($breadcrumbs_array)) {
//the breadcrumbs may be empty due to settings
return self::get_breadcrumbs($breadcrumbs_array); //generate the breadcrumbs
} else {
return '';
}
}
/**
* get the breadcrumbs for the taxonomy page. It will also add 1 parent taxonomy if it's available
* @param $current_term_obj
* @return string
*/
static function get_taxonomy_breadcrumbs($current_term_obj) {
// check to see if the taxonomy has a parent and add it (only if enabled via the theme panel)
if (!empty($current_term_obj->parent) and td_util::get_option('tds_breadcrumbs_show_parent') != 'hide') {
$current_term_parent_obj = get_term($current_term_obj->parent, $current_term_obj->taxonomy);
$current_term_parent_url = get_term_link($current_term_parent_obj, $current_term_obj->taxonomy);
if (!is_wp_error($current_term_parent_url)) {
$breadcrumbs_array[] = array(
'title_attribute' => '',
'url' => $current_term_parent_url,
'display_name' => $current_term_parent_obj->name
);
}
}
// add the current taxonomy
$breadcrumbs_array[] = array(
'title_attribute' => '',
'url' => '',
'display_name' => $current_term_obj->name
);
return self::get_breadcrumbs($breadcrumbs_array); //generate the breadcrumbs
}
/**
* WARNING: this function also runs in the page-pagebuilder-latest.php in a FAKE LOOP - this means that wordpress functions
* like is_category DO NOT WORK AS EXPECTED when you use for example a category filter for the loop, is_category returns true
*/
static function get_pagination() {
global $wp_query;
if (td_global::$current_template == '404') {
return;
}
$pagenavi_options = self::pagenavi_init();
$request = $wp_query->request;
$posts_per_page = intval(get_query_var('posts_per_page'));
$paged = intval(get_query_var('paged'));
$numposts = $wp_query->found_posts;
$max_page = $wp_query->max_num_pages;
// hack for category pages - pagination
// we also have to check for page-pagebuilder-latest.php template because we are running there in a FAKE loop and if the category
// filter is active for that loop, WordPress believes that we are on a category
if(!is_admin() and td_global::$current_template != 'page-homepage-loop' and is_category()) {
$numposts = $wp_query->found_posts - td_api_category_top_posts_style::_helper_get_posts_shown_in_the_loop(); // fix the pagination, we have x less posts because the rest are in the top posts loop
$max_page = ceil($numposts / $posts_per_page);
}
if(empty($paged) || $paged == 0) {
$paged = 1;
}
$pages_to_show = intval($pagenavi_options['num_pages']);
$larger_page_to_show = intval($pagenavi_options['num_larger_page_numbers']);
$larger_page_multiple = intval($pagenavi_options['larger_page_numbers_multiple']);
$pages_to_show_minus_1 = $pages_to_show - 1;
$half_page_start = floor($pages_to_show_minus_1/2);
$half_page_end = ceil($pages_to_show_minus_1/2);
$start_page = $paged - $half_page_start;
if($start_page <= 0) {
$start_page = 1;
}
$end_page = $paged + $half_page_end;
if(($end_page - $start_page) != $pages_to_show_minus_1) {
$end_page = $start_page + $pages_to_show_minus_1;
}
if($end_page > $max_page) {
$start_page = $max_page - $pages_to_show_minus_1;
$end_page = $max_page;
}
if($start_page <= 0) {
$start_page = 1;
}
$larger_per_page = $larger_page_to_show*$larger_page_multiple;
$larger_start_page_start = (self::td_round_number($start_page, 10) + $larger_page_multiple) - $larger_per_page;
$larger_start_page_end = self::td_round_number($start_page, 10) + $larger_page_multiple;
$larger_end_page_start = self::td_round_number($end_page, 10) + $larger_page_multiple;
$larger_end_page_end = self::td_round_number($end_page, 10) + ($larger_per_page);
if($larger_start_page_end - $larger_page_multiple == $start_page) {
$larger_start_page_start = $larger_start_page_start - $larger_page_multiple;
$larger_start_page_end = $larger_start_page_end - $larger_page_multiple;
}
if($larger_start_page_start <= 0) {
$larger_start_page_start = $larger_page_multiple;
}
if($larger_start_page_end > $max_page) {
$larger_start_page_end = $max_page;
}
if($larger_end_page_end > $max_page) {
$larger_end_page_end = $max_page;
}
if($max_page > 1 || intval($pagenavi_options['always_show']) == 1) {
$pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), $pagenavi_options['pages_text']);
$pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text);
echo '<div class="page-nav td-pb-padding-side">';
previous_posts_link($pagenavi_options['prev_text']);
if ($start_page >= 2 && $pages_to_show < $max_page) {
$first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['first_text']);
echo '<a href="'.esc_url(get_pagenum_link()).'" class="first" title="'.$first_page_text.'">'.$first_page_text.'</a>';
if(!empty($pagenavi_options['dotleft_text']) && ($start_page > 2)) {
echo '<span class="extend">'.$pagenavi_options['dotleft_text'].'</span>';
}
}
// if($larger_page_to_show > 0 && $larger_start_page_start > 0 && $larger_start_page_end <= $max_page) {
// for($i = $larger_start_page_start; $i < $larger_start_page_end; $i+=$larger_page_multiple) {
// $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
// echo '<a href="'.esc_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
// }
// echo '<span class="extend">'.$pagenavi_options['dotleft_text'].'</span>';
// }
for($i = $start_page; $i <= $end_page; $i++) {
if($i == $paged) {
$current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['current_text']);
echo '<span class="current">'.$current_page_text.'</span>';
} else {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
echo '<a href="'.esc_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
}
}
// if($larger_page_to_show > 0 && $larger_end_page_start < $max_page) {
// echo '<span class="extend">'.$pagenavi_options['dotright_text'].'</span>';
// for($i = $larger_end_page_start; $i <= $larger_end_page_end; $i+=$larger_page_multiple) {
// $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
// echo '<a href="'.esc_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
// }
// }
if ($end_page < $max_page) {
if(!empty($pagenavi_options['dotright_text']) && ($end_page + 1 < $max_page)) {
echo '<span class="extend">'.$pagenavi_options['dotright_text'].'</span>';
}
$last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['last_text']);
echo '<a href="'.esc_url(get_pagenum_link($max_page)).'" class="last" title="'.$last_page_text.'">'.$last_page_text.'</a>';
}
next_posts_link($pagenavi_options['next_text'], $max_page);
if(!empty($pages_text)) {
echo '<span class="pages">'.$pages_text.'</span>';
}
echo '</div>';
}
}
static function td_round_number($num, $tonearest) {
return floor($num/$tonearest)*$tonearest;
}
//the default options
static function pagenavi_init() {
$pagenavi_options = array();
$pagenavi_options['pages_text'] = __td('Page %CURRENT_PAGE% of %TOTAL_PAGES%', TD_THEME_NAME);
$pagenavi_options['current_text'] = '%PAGE_NUMBER%';
$pagenavi_options['page_text'] = '%PAGE_NUMBER%';
$pagenavi_options['first_text'] = __td('1');
$pagenavi_options['last_text'] = __td('%TOTAL_PAGES%');
if (is_rtl()) {
$pagenavi_options['next_text'] = '<i class="td-icon-menu-right"></i>';
$pagenavi_options['prev_text'] = '<i class="td-icon-menu-left"></i>';
} else {
$pagenavi_options['next_text'] = '<i class="td-icon-menu-right"></i>';
$pagenavi_options['prev_text'] = '<i class="td-icon-menu-left"></i>';
}
$pagenavi_options['dotright_text'] = __td('...');
$pagenavi_options['dotleft_text'] = __td('...');
$pagenavi_options['num_pages'] = 3;
$pagenavi_options['always_show'] = 0;
$pagenavi_options['num_larger_page_numbers'] = 3;
$pagenavi_options['larger_page_numbers_multiple'] = 1000;
return $pagenavi_options;
}
static function no_posts() {
if (td_global::$custom_no_posts_message === false) {
return '';
} else {
$buffy = '<div class="no-results td-pb-padding-side">';
if (empty(td_global::$custom_no_posts_message)) {
$buffy .= '<h2>' . __td('No posts to display', TD_THEME_NAME) . '</h2>';
} else {
$buffy .= '<h2>' . td_global::$custom_no_posts_message . '</h2>';
}
$buffy .= '</div>';
return $buffy;
}
}
}
Loop.php:
<?php
/**
* If you are looking for the loop that's handling the single post page (single.php), check out loop-single.php
**/
// $global_flag_to_hide_no_post_to_display - comes from page-category-big-grid.php and is a flag to hide the 'No posts to display' message if on category page there are between 1 and 5 posts
global $loop_module_id, $loop_sidebar_position, $global_flag_to_hide_no_post_to_display;
///if we are in wordpress loop; used by quotes in blocks to check if the blocks are displayed in blocks or in loop
td_global::$is_wordpress_loop = true;
$td_template_layout = new td_template_layout($loop_sidebar_position);
if (empty($loop_module_id)) { //not sure if we need a default here
$loop_module_id = 1;
}
$td_module_class = td_util::get_module_class_from_loop_id($loop_module_id);
//disable the grid for some of the modules
$td_module = td_api_module::get_by_id($td_module_class);
if ($td_module['uses_columns'] === false) {
$td_template_layout->disable_output();
}
if (have_posts()) {
while ( have_posts() ) : the_post();
echo $td_template_layout->layout_open_element();
if (class_exists($td_module_class)) {
$td_mod = new $td_module_class($post);
echo $td_mod->render();
} else {
td_util::error(__FILE__, 'Missing module: ' . $td_module_class);
}
echo $td_template_layout->layout_close_element();
$td_template_layout->layout_next();
endwhile; //end loop
echo $td_template_layout->close_all_tags();
} else {
/**
* no posts to display. This function generates the __td('No posts to display').
* the text can be overwritten by the themplate using the global @see td_global::$custom_no_posts_message
*/
echo td_page_generator::no_posts();
}