WordPress 分页不起作用 第 2 页与第 1 页相同 [英] WordPress Pagination not working Page 2 same as Page 1

查看:60
本文介绍了WordPress 分页不起作用 第 2 页与第 1 页相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 WordPress 分页正常工作.

我使用了不同的插件并尝试调整 pagination.php 函数中的代码无济于事.

无论我到目前为止使用什么插件或调整,第 2 页、第 3 页等总是显示相同的帖子集.

这里是 pagination.php 中的代码

<div class="mdnw_pagination"><?php if(function_exists('wp_paginate')) :wp_paginate();;否则:?><div class="p 按钮"><?php next_posts_link(__('« Previous Posts', 'skeleton'));?></div><div class="m button"><?php previous_posts_link(__('Next Posts »', 'skeleton'));?></div><?php endif;?>

<!-- </上一个/更多条目-->

这是主页博客模板的代码:

<?phpwp_reset_query();全局 $paged;全局 $template_file;$cat_string = '';$格式 = '';if( get_post_custom_values('blog_post_count') ) :$post_array = get_post_custom_values('blog_post_count');$post_count = join(',', $post_array);别的 :$post_count = -1;万一;/* 获取类别过滤器 */if(get_custom_field('blog_category_filter')) :$cats = get_custom_field( 'blog_category_filter' );foreach ( $cats as $cat ) {$acats[] = $cat;}$cat_string = join(',', $acats);万一;$args=数组('cat'=>$cat_string,//查询猫 ID(因为你不能使用多个名称或 slugs...疯狂的 WP!)'posts_per_page'=>$post_count,//设置每页的帖子数限制'paged'=>$paged,//基本的分页内容.);query_posts($args);?><?php if ( have_posts() ) : while ( have_posts() ) : the_post();?><?php get_template_part('includes/format', $format);?><?php endwhile;其他:?><div class="post"><p><?php _e('抱歉,没有符合您条件的帖子.', 'skeleton') ?></p></div><!--/.post --><?php endif;?><?php get_template_part('includes/element', '分页');?><?php wp_reset_query();?>

我应该在任一文件中更改哪些内容以使其显示除第一页之外的任何其他内容?

我会更改阅读窗格设置,但查询帖子功能使用我不知道的动态值.

我可以如何更改或更改什么才能使其正常工作?

我在此页面上尝试了解决方案 https://wordpress.stackexchange.com/questions/105977/wordpress-pagination-not-working-always-showing-first-pages-content,但无济于事:

这是我将代码更改为:

$paged,//基本的分页内容.);$your_query = new WP_Query( $args);?><?php if ( $your_query->have_posts() ) : while ( $your_query->have_posts() ) : $your_query->the_post();?><?php get_template_part('includes/format', $format);?><?php endwhile;其他:?><div class="post"><p><?php _e('抱歉,没有符合您条件的帖子.', 'skeleton') ?></p></div><!--/.post --><?php endif;?><?php get_template_part('includes/element', '分页');?><?php wp_reset_query();?>

解决方案

我修好了.

我在这里找到了修复:http://themeforest.net/forums/thread/pagination-on-wordpress-static-page-set-to-front-page/28120

而不是这样做:

 $paged = (get_query_var('paged')) ?get_query_var('paged') : 1;query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );

我是这样做的:

if ( get_query_var('paged') ) {$paged = get_query_var('paged');} elseif ( get_query_var('page') ) {$paged = get_query_var('page');} 别的 {$paged = 1;}query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );

现在可以了!

I'm trying to get WordPress Pagination Working.

I've used different plugins and tried tweaking the code in the pagination.php function to no avail.

No matter what plugin or tweak I've used so far, Pages 2, 3 etc always displays the same set of posts.

Here is the code in the pagination.php

<!-- Previous / More Entries -->        
<div class="mdnw_pagination">

<?php if(function_exists('wp_paginate')) :
    wp_paginate();
; else : ?>
<div class="p button"><?php next_posts_link(__('« Previous Posts', 'skeleton')); ?></div>
<div class="m button"><?php previous_posts_link(__('Next Posts »', 'skeleton')); ?></div>
<?php endif; ?>

</div>
<!-- </Previous / More Entries -->

Here is the code for the blog template for the home page:

<!-- THE POST QUERY -->
                        <?php 

                    wp_reset_query();

                    global $paged;
                    global $template_file;
                    $cat_string = '';
                    $format = '';

                    if( get_post_custom_values('blog_post_count') ) :  
                        $post_array = get_post_custom_values('blog_post_count');
                        $post_count = join(',', $post_array);
                    else : 
                        $post_count = -1;
                    endif;

                    /* Get Category Filter */
                    if(get_custom_field('blog_category_filter' )) :
                        $cats = get_custom_field( 'blog_category_filter' );
                        foreach ( $cats as $cat ) {
                            $acats[] = $cat;                
                        }
                        $cat_string = join(',', $acats);                    
                    endif;

                    $args=array(
                        'cat'=>$cat_string,            // Query for the cat ID's (because you can't use multiple names or slugs... crazy WP!)
                        'posts_per_page'=>$post_count, // Set a posts per page limit
                        'paged'=>$paged,               // Basic pagination stuff.
                       );

                    query_posts($args); ?>

                    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> 

                        <?php get_template_part( 'includes/format', $format ); ?>

                    <?php endwhile; else: ?>

                        <div class="post">
                              <p><?php _e('Sorry, no posts matched your criteria.', 'skeleton') ?></p>
                        </div><!-- /.post -->

                    <?php endif; ?>  
                    <?php get_template_part( 'includes/element', 'pagination' ); ?>                    
                    <?php wp_reset_query(); ?>                  

                </div>

What should I change in either file to get it to show any other content but the first page?

I would change the reading pane settings but the query posts function uses a dynamic value that I'm unaware of.

How or what can I change to get it working?

I tried the solution on this page https://wordpress.stackexchange.com/questions/105977/wordpress-pagination-not-working-always-showing-first-pages-content , but to no avail:

Here is what I changed the code to:

<?php 

                    wp_reset_query();

                    global $paged;
                    global $template_file;
                    $cat_string = '';
                    $format = '';

                    if( get_post_custom_values('blog_post_count') ) :  
                        $post_array = get_post_custom_values('blog_post_count');
                        $post_count = join(',', $post_array);
                    else : 
                        $post_count = -1;
                    endif;

                    /* Get Category Filter */
                    if(get_custom_field('blog_category_filter' )) :
                        $cats = get_custom_field( 'blog_category_filter' );
                        foreach ( $cats as $cat ) {
                            $acats[] = $cat;                
                        }
                        $cat_string = join(',', $acats);                    
                    endif;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
                    $args=array(
                        'cat'=>$cat_string,            // Query for the cat ID's (because you can't use multiple names or slugs... crazy WP!)
                        'posts_per_page'=> 9, // Set a posts per page limit
                        'paged'=>$paged,               // Basic pagination stuff.
                       );

                    $your_query = new WP_Query( $args ); ?>

                    <?php if ( $your_query->have_posts() ) : while ( $your_query->have_posts() ) : $your_query->the_post(); ?>  

                        <?php get_template_part( 'includes/format', $format ); ?>

                    <?php endwhile; else: ?>

                        <div class="post">
                              <p><?php _e('Sorry, no posts matched your criteria.', 'skeleton') ?></p>
                        </div><!-- /.post -->

                    <?php endif; ?>  
                    <?php get_template_part( 'includes/element', 'pagination' ); ?>                    
                    <?php wp_reset_query(); ?>  

解决方案

I fixed it.

I found the fix here: http://themeforest.net/forums/thread/pagination-on-wordpress-static-page-set-to-front-page/28120

Instead of doing this:

   $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );

I did this:

if ( get_query_var('paged') ) {

$paged = get_query_var('paged');

} elseif ( get_query_var('page') ) {

$paged = get_query_var('page');

} else {

   $paged = 1;

}

query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );

Now it works!

这篇关于WordPress 分页不起作用 第 2 页与第 1 页相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆