我正在尝试修复一个具有以下设置的主题:在每个页面上,用户可以选择列出帖子,而不是页面内容。问题是分页在这个页面上不起作用,即使相同的功能在主查询(主页)上也可以正常工作。当我说分页不起作用时,我的意思是当我点击第2页时,我得到的帖子和第1页上的一样。
这是page.php
:
<?php get_header(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$display_posts = get_post_meta($post->ID,\'zephyr_display_posts\', true);
$zephyr_full_content = get_post_meta($post->ID,\'zephyr_full_content\', true);
$zephyr_post_columns = get_post_meta($post->ID,\'zephyr_meta_box_columns\', true);
if ( $zephyr_post_columns == \'\' ) { $zephyr_post_columns = \'col-md-6\'; }
if ( $display_posts == \'on\' ) {
if ( $posts_slider == \'on\' ) { get_template_part( \'templates/post\', \'slider\'); }
if ( $zephyr_page_layout == \'no-sidebar\' ) {
get_template_part(\'templates/content\', \'nosidebar\');
} else {
get_template_part(\'templates/content\', \'\');
}
} else {
if ( $zephyr_page_layout == \'no-sidebar\' ) {
get_template_part(\'templates/content\', \'page-nosidebar\');
} else {
get_template_part(\'templates/content\', \'page\');
}
} ?>
<?php endwhile; else : ?>
<div class="col-md-offset-2 col-xs-offset-2 col-sm-offset-2 col-md-10 col-xs-10 col-sm-10">
<h1><?php _e(\'No matching posts were found\', \'zephyr\'); ?></h1>
</div>
<?php endif; ?>
<?php if ( $zephyr_page_layout !== \'no-sidebar\' ) { get_template_part(\'templates/sidelist\', \'\'); } ?>
<?php get_footer(); ?>
那么这就是
content.php
:
<?php // building query
$zephyr_cat = get_post_meta($post->ID, \'zephyr_category\', true);
if ( $zephyr_cat == 0 ) {
$zephyr_q = new WP_query(\'posts_per_page=\'.get_option(\'posts_per_page\'));
} else {
$zephyr_q = new WP_query(\'cat=\'.$zephyr_cat);
}
global $zephyr_i;
$pages = $zephyr_q->max_num_pages;
$zephyr_i = 0;
if ( $zephyr_q->have_posts() ) : while ( $zephyr_q->have_posts() ) : $zephyr_q->the_post(); ?>
<?php
if ( $zephyr_post_layout == \'post-masonry\' ) {
$zephyr_i++;
get_template_part( \'templates/post\', \'masonry\'.get_post_format() );
} else {
get_template_part( \'templates/post\', get_post_format() );
}
zephyr_get_ads_post($zephyr_q);
endwhile; else : ?>
<h2><?php _e(\'No posts found, go \', \'zephyr\'); ?> <a href="<?php echo home_url(); ?>" title="<?php bloginfo(\'name\'); ?>"><?php _e(\'home\', \'zephyr\'); ?></a>?</h2>
<?php endif; ?>
<div class="clearfix"></div>
<?php zephyr_pagination($pages) ?>
</div>
最后,这是来自的分页函数
functions.php
:
function zephyr_pagination($pages = \'\', $range = 2) {
if ( !get_theme_mod(\'zephyr_infinite\') ) {
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == \'\') {
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages) {
$pages = 1;
}
}
if(1 != $pages) {
echo "<div class=\'row paginationrow\'>";
echo "<div class=\'zephyr-pagination col-md-10 col-md-offset-2\'>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a class=\'first\' href=\'".get_pagenum_link(1)."\'>".__(\'First\', \'zephyr\')."</a>";
if($paged > 1 && $showitems < $pages) echo get_previous_posts_link(__(\'Prev\', \'zephyr\'));
for ($i=1; $i <= $pages; $i++) {
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
echo ($paged == $i)? "<span class=\'current\'>".$i."</span>":"<a href=\'".get_pagenum_link($i)."\' class=\'inactive\' >".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo get_next_posts_link(__(\'Next\', \'zephyr\'));
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href=\'".get_pagenum_link($pages)."\'>".__(\'Last\', \'zephyr\')."</a>";
echo "</div>\\n";
echo "</div>\\n";
}
}
}
正如我所说的,主页上的一切都很好,分页只在辅助页面上出现(启用列表帖子选项)。