简体   繁体   中英

Wordpress Pagination does not work

I am trying to create a wordpress theme, but I am not able to make the pagination work on the live version. On the localhost it's working just as expected, but on the live version it gives a 404 page each time. I know that there is a lot of answers about this topic, but I was not able to fix my problem. I've already tryed the following topics, among so many others but none of them helped me:

I would like to know if you guys can help me to figure out what I am missing here. I am trying to show my navigation panel at index file(my blog page).

get_header(); ?>

<div id="primary" class="container">
    <main id="main" class="col-xs-12">
        <h3 class="title text-center">Notícias:</h3>

        <?php 
            global $wp_query;
            query_posts(
                array_merge( array(
                    'post_type' => 'news',
                    'orderby' => 'date',
                    'order' => 'DESC',
                    'posts_per_page' => 3
                ),$wp_query->query)
            );

            while($wp_query->have_posts()) :
            $wp_query->the_post();

            get_template_part('template-parts/content', 'news');

            endwhile; 
        ?>
        <div class="text-center paginate">
            <?php 
                if(function_exists('wp_paginate')):
                    wp_paginate();  
                endif;
             ?>
        </div> <!-- .tect-center / Paginate-->
        <?php  wp_reset_postdata();  ?>
    </main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();

Right now I am using Wp-paginate plugin, but using paginate_links() functions gives me the same error, but both of them work on localhost. For the paginate link I've used the example from docs:

https://codex.wordpress.org/Function_Reference/paginate_links .

Can somenon help me on that, please?

Since it's working on your localhost flushing permalinks might solve your issue.

Step 1: In wordpress dashboard "Settings > Permalinks".

Step 2: Scroll down and click "Save Changes", no need to change anything.

Once done, rewrite rules and permalinks will be flushed.

Try to use below code.

I have used WP_Query function to get desired result - https://codex.wordpress.org/Class_Reference/WP_Query

<?php 

$args = array(
    'post_type' => 'post',
    'orderby' => 'date',
    'order' => 'DESC',
    'posts_per_page' => 3
    );

$the_query = new WP_Query($args);

while($the_query->have_posts()) :
    $the_query->the_post();

    get_template_part('template-parts/content', 'news');

endwhile; ?>
<div class="text-center paginate">
    <?php 
        if(function_exists('wp_paginate')):
            wp_paginate();  
        endif;
     ?>
 </div> <!-- .tect-center / Paginate-->
<?php  wp_reset_postdata();  ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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