简体   繁体   中英

WordPress Blog Pagination Not Working

I'm still stuck on this issue..

The pagination on my WordPress blog is not working - http://www.example.com/news

When you click a different page number it updates the URL (and page title) correctly but it does not show different posts.

Ive tried:

  • Disabling all plug-ins
  • Changing the permalink structure
  • Changing the number of blog posts displayed in Settings>Reading
  • Changing http://www.example.com/recall-news to a different path to avoid conflicting with a post category named "news"

Nothing has worked for me.

I've seen many solutions for a custom query, but I'm using the posts page that you set in Settings>Reading>Posts Page so I did not write any code to display the posts on this page.

  • What WordPress file do I modify to fix the blog pagination in this case? I'm guessing I can add something to functions.php, but I haven't found a solution yet.

UPDATE: I have not found the solution yet. I know I can do it by writing my own query but I want to stick with the default WP blog.

Check your WP loop in the category.php file (aka archive.php). It must contain the following:

if (have_posts()) : while (have_posts()) : the_post();

and finished with:

endwhile; endif;

I have played with the "posts pages" too but I'm getting no result.

Only working solution for me was a custome query in combination with the Page-Navi Plugin.

In my template i have the following code:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
        'post_type'         => 'post',
        'orderby'           => 'date',
        'order'             => 'DESC',
        'post_status'       => 'publish',
        'posts_per_page'    => 5,
        'paged'             => $paged,
    );
    $q = new WP_Query( $args );

    if ( $q->have_posts() ) {
        $displaylist = '<div class="list-group">';

        while ( $q->have_posts() ) {
            $q->the_post();

            // build up your entry

            unset( $displayTag );
        }

        $displaylist .= '</div>';

        echo( $displaylist );

        wp_pagenavi( array( 'query' => $q ) );

        wp_reset_postdata();
    }
?>

With the post_per_page i manage the entries per site. In while loop i build up the entries that should be showed.

There is no guarantee that your issue is WordPress related. However, because you haven't given a very general question, I am going to give you a very general answer. This should aid you in figuring out what is wrong and solving it yourself.

  1. Check out underscores . Download it and review the templates (like index.php , archive.php , etc.) to see if you're missing something that underscores includes. The nice thing about underscores is that it's all the basic stuff you need to create a running theme, with no frills. So, if it's there and not in your code, it may be worth exploring. Take special care for any code blocks relating to have_posts .

  2. It may not actually be anything wrong with your theme. Try testing another theme (say, underscores, which you've conveniently downloaded) to see if it has pagination working and intact. If it does, then, you're in luck... That means you just have to dig a bit deeper to reconcile what's wrong with your code that's right with underscores.

  3. If you've discovered that it's not something wrong with your theme but in fact something wrong with your server configuration, that's also something of a relief, in a matter of speaking. It means that you should theoretically be able to test your installation somewhere else, or reinstall your server, and make it work. Before going that far, try to simply reinstall your version of WordPress. Who knows... It could work.

You should pass the "page"/"paged" var in the query_post function:

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('paged' => $paged));
if (have_posts()) : while ( have_posts() ) : the_post(); ?>
<!--Your HTML-->.
<?php endwhile; endif;  wp_reset_query(); ?>

Can you try using Wp-Pagenavi for generating your pagination? That way we can at least check if the problem is the default pagination or just some error in the coding that is not filling the paged variable correctly

Try this

    global $wpdb;

    $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
    $limit = 20;
    $offset = ( $pagenum - 1 ) * $limit;
    //$entries = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}design_information LIMIT $offset, $limit" );
     $entries = $wpdb->get_results("Select * From design_information ORDER BY id DESC LIMIT $offset, $limit",ARRAY_A);

echo '<div class="wrap">';
<table class="widefat">
    <thead>
        <tr>
           <th>SNo.</th><th>Layout</th><th>Org Description</th>
        </tr>
    </thead>

    <tbody>
        <?php if( $entries ) { ?>

            <?php
            $count = 1;
            $class = '';
    //echo "<pre>";
    //print_r($entries);
    for($i=0;$i<count($entries); $i++)
    {

$pid=$entries[$i]['id'];
                $class = ( $count % 2 == 0 ) ? ' class="alternate"' : '';
          ?>
            <tr<?php echo $class; ?>>
                <td>
              <?php echo $entries[$i]['id'];
                //echo $count; 
                $count++;?>
          </td>
<td>
      <?php echo $entries[$i]['layout'];?>
  </td>
  <td> 
      <?php echo $entries[$i]['org_description'];?>
  </td>

  </tr>
</table>

Create a file archive-learning.php in your theme.

That mean post_type is "learning"

 <?php if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); } elseif ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); } else { $paged = 1; } <?php $custom_args = array( 'post_type' => 'learning', 'post_status' => 'public', 'orderby' => 'date', 'order' =>'DESC', 'posts_per_page'=>12,//limit 6 'paged' => $paged ); $wp_query = new WP_Query( $custom_args ); $getPosts = get_posts($custom_args); ?> <?php if ($getPosts) : ?> <?php global $post,$wp_query;?> <?php foreach ($getPosts as $post): ?> <?php setup_postdata($post);?> <?php echo "your content here";?> <?php endforeach;?> <?php else : endif; ?> <div class="pagenation"><?php if (function_exists(custom_pagination)) {custom_pagination($wp_query->max_num_pages,"",$paged);} ?></div></div> <?php wp_reset_postdata(); ?>
go to file functions.php and create function custom_pagination

 function custom_pagination($numpages = '', $pagerange = '', $paged='') { if (empty($pagerange)) { $pagerange = 2; } /* * This first part of our function is a fallback * for custom pagination inside a regular loop that * uses the global $paged and global $wp_query variables. * * It's good because we can now override default pagination * in our theme, and use this function in default queries * and custom queries. */ global $paged; if (empty($paged)) { $paged = 1; } if ($numpages == '') { global $wp_query; $numpages = $wp_query->max_num_pages; if(!$numpages) { $numpages = 1; } } /** * We construct the pagination arguments to enter into our paginate_links * function. */ $pagination_args = array( 'base' =>add_query_arg('page','%#%'), 'format' => 'page/%#%', 'total' => $numpages, 'current' => $paged, 'show_all' => False, 'end_size' => 1, 'mid_size' => $pagerange, 'prev_next' => True, 'prev_text' => __('&laquo;'), 'next_text' => __('&raquo;'), 'type' => 'plain', 'add_args' => false, 'add_fragment' => '' ); $paginate_links = paginate_links($pagination_args); if ($paginate_links) { echo "<nav class='custom-pagination'>"; //echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> "; echo $paginate_links; echo "</nav>"; } }

This usually happens when you use the custom permalink structure /%category%/%postname%/ which was indeed my case.

This video and its text version fixed it for me like a charm.

In short, installing this plugin solved my problem:

https://wordpress.org/plugins/post-category-prev-next-link-fix/#description

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