WordPress Blog Pagination Not Working

2019-06-16 06:46发布

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.

7条回答
倾城 Initia
2楼-- · 2019-06-16 07:12

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;
查看更多
唯我独甜
3楼-- · 2019-06-16 07:13

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.

查看更多
疯言疯语
4楼-- · 2019-06-16 07:15

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>
查看更多
老娘就宠你
5楼-- · 2019-06-16 07:21

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(); ?>
查看更多
做个烂人
6楼-- · 2019-06-16 07:21

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>";
  }

}

查看更多
趁早两清
7楼-- · 2019-06-16 07:26

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

查看更多
登录 后发表回答