简体   繁体   English

WordPress类别分页不起作用

[英]WordPress Category Pagination not working

I have two custom post types from the archive.php One is archive-slug.php and the other is category-slug.php. 我有来自archive.php的两种自定义帖子类型,一种是archive-slug.php,另一种是category-slug.php。 The pagination works on the archive-slug.php but the same code on the category-slug.php won't even show. 分页在archive-slug.php上有效,但类别-slug.php上的相同代码甚至都不会显示。 I'm somewhat new to Wordpress and php so i'm sure i'm missing something here, I just don't know what? 我是Wordpress和php的新手,所以我确定我在这里缺少什么,我只是不知道什么?

<?php 
// Custom Post Type
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
        'post_type' => 'available_dogs',
        'category_name' => 'adopted-dogs',
        'posts_per_page'=> 9,
        'paged'=> $paged
    );
    $the_query = new WP_Query( $args ); ?>
        <?php if ( $the_query->have_posts() ) : ?>
            <?php while ( $the_query->have_posts() ) : $the_query->the_post();     ?>   
            <div class="dog-info-box col-lg-4 col-sm-6 col-xs-12">...</div>  
            <?php endwhile; ?>
            <!-- end of the loop -->
            <?php wp_reset_postdata(); ?>
        <?php else : ?>
            <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
        <?php endif; ?>
    </div>
<?php 
// Get the pagination
fusion_pagination( $pages = '', $range = 2 );
?> 
<?php if( $sidebar_exists == true ): ?>
<?php wp_reset_query(); ?>


As I want to inform you that when you create a file " 谨此通知您,创建文件时,“

category-slug.php  : it's an default template.No need to add the query posts.
It will display the posts of the category whose slug is added in file like category-slug.php. 它将显示类别的帖子,该类别的条目添加到文件类别-slug.php中。
Here is the modifying code. 这是修改代码。
  if (have_posts() ) :while ( have_posts() ) : the_post(); the_content();//content is going on. endwhile; 
//pagination function
fusion_pagination( $pages = '', $range = 2 );
else : _e( 'Sorry, no posts matched your criteria.' );
endif;
\n if (have_posts() ) :while ( have_posts() ) : the_post(); the_content();//content is going on. endwhile;
//pagination function
fusion_pagination( $pages = '', $range = 2 );
else : _e( 'Sorry, no posts matched your criteria.' );
endif;

Precaution :1:Pagination code should be placed just before of the while loop. 注意事项:1:分页代码应放在while循环之前。
2:In your code pagination code have been place after the endif that's why it is not working. 2:在您的代码中,分页代码已放在endif之后,这就是为什么它不起作用的原因。
Thanking you. 感谢您。

I used this code and got it working. 我使用了这段代码并使它工作。 It's not pretty but it will do for now. 它不是很漂亮,但是现在就可以了。 For what ever reason when I try to use it after the loop it doesn't work. 出于什么原因,当我尝试在循环后使用它时,它将不起作用。 When I use it after the endif it works. 当我使用它后,它会起作用。

    <?php if ($the_query->max_num_pages > 1) { // check if the max number of    pages is greater than 1  ?>
      <nav class="prev-next-posts">
         <div class="prev-posts-link">
            <?php echo get_next_posts_link( 'Older Entries', $the_query->max_num_pages ); // display older posts link ?>
         </div>
         <div class="next-posts-link">
            <?php echo get_previous_posts_link( 'Newer Entries' ); // display newer posts link ?>
         </div>
      </nav>
    <?php } ?>

Please follow this steps. 请按照以下步骤操作。 1: Please make sure, your category have the posts. 1:请确保您的类别中有帖子。
2: If your category slug is "test" then your file name should be " category-test.php . if any confusion then please let me know. 2:如果您的类别标签是“ test”,那么您的文件名应该是“ category-test.php”。如果有任何混淆,请告诉我。

3: See the code and write in file. 3:查看代码并写入文件。

if(have_posts()) :
while(have_posts()): the_post();
the_title();
the_content();
endwhile;
//pagination of wp previous_posts_link( '« Newer Entries' ); next_posts_link( 'Older Entries »', 0 );
endif;

Note: 注意:
1:Please place this code in file and run if it will running successfully, then we will add the designing part. 1:请将此代码放入文件中并运行,如果运行成功,则将添加设计部分。
2: If you can share the website URL then I can also give suitable solution because then I can seen the category slug etc . 2:如果您可以共享网站URL,那么我也可以提供合适的解决方案,因为这样我就可以看到类别slug等。
Please let me know if still needs problem. 请让我知道是否仍然有问题。
Thanking. 谢谢

I finally fixed a variation of this same issue. 我终于解决了同一问题的一个变体。

This issue was occurring with category archive pagination. 此问题与类别存档分页有关。

Initially thought it was within the Loop - turns out the theme I was working on had these filters in a file, custom.php, which manually rewrote the permalink structure. 最初以为它在循环之内-原来我正在研究的主题是将这些过滤器保存在文件custom.php中,该文件手动重写了永久链接结构。

add_filter('category_link', 'themename_change_archive_link', 100, 2);
add_action('init', 'themename_archive_rewrite', 50);

Pagination didn't like that due to what looks like a conflict with a recent WooCommerce update , so I removed these filters, used the Custom Permalink plugin to rewrite the category permalinks, and it worked! 由于与最近的WooCommerce更新似乎有冲突 ,因此分页不喜欢这种方式,因此我删除了这些过滤器,使用Custom Permalink插件重写了类别永久链接,它可以正常工作! Now I have a custom permalink structure AND functioning category pagination. 现在,我有了一个自定义的永久链接结构和功能类别分页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM