Wordpress分页只显示page1

时间:2016-12-19 18:47:55

标签: php wordpress pagination

我是wordpress的新手,分页对我来说效果不佳。它工作正常,直到今天,我不知道为什么。 现在,当我点击下一页时,链接转到第2页,但我仍然看到第1页的帖子。我有functions.php,home.php和index.php页面 我的代码粘贴在下面。知道我做错了吗?

的functions.php

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'            => get_pagenum_link(1) . '%_%',
    'format'          => 'page/%#%',
    'total'           => $numpages,
    'current'         => $paged,
    'show_all'        => False,
    'end_size'        => 1,
    'mid_size'        => $pagerange,
    'prev_next'       => True,
    'prev_text'       => __('«'),
    'next_text'       => __('»'),
    '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>";
  }

}

home.php

<content class="main-content" style="background-color: #F2F1EC; background: #F2F1EC;">
   <div class="row posts">
   <?php    $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;

  $query_args = array(
      'post_type' => 'post',
      'posts_per_page' => 6,
      'paged' => $paged,
      'page' => $paged
    );

  $the_query = new WP_Query( $query_args ); ?>

  <?php if ( $the_query->have_posts() ) : ?>

    <!-- the loop -->
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
       <div class="col-lg-4 col-md-4 col-sm-6 space-down-20">
        <a class="blog-post" href="<?php the_permalink(); ?>">
          <div class="thumbnail">
           <div class="image">
           <?php if ( has_post_thumbnail() ) {
         the_post_thumbnail( 'full', array( 'class' => 'featured-image' ) );
        } else { ?> <img src="home_header.jpg" class="featured-image"> <?php } ?>
           </div>
           <div class="caption">
            <h6 class="no-line"><?php the_time('F jS, Y');?></h6><br />
            <h3 class="no-line"><?php the_title();?></h3><br />
            <?php if(has_excerpt()){
                ?>
                <h5 class="text-muted"><strong><?php the_excerpt();?></strong></h5>
            <?php   
                }
            ?>
           </div>
        </div>
         </a>
       </div> 
       <?php endwhile; ?>
    <!-- end of the loop -->
</div>
<div class="row space-down-20 space-left-20">
<div class="col-sm-12">
    <!-- pagination here -->
    <?php
      if (function_exists(custom_pagination)) {
        custom_pagination($the_query->max_num_pages,"",$paged);
      }
    ?>

  <?php wp_reset_postdata(); ?>

  <?php else:  ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
  <?php endif; ?>
</div>   
</div>  

的index.php

<content class="main-content" style="background-color: #F2F1EC; background: #F2F1EC;">
   <div class="row posts">
    <?php 

  $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

  $custom_args = array(
      'post_type' => 'post',
      'posts_per_page' => 6,
      'paged' => $paged
    );

  $custom_query = new WP_Query( $custom_args ); ?>

  <?php if ( $custom_query->have_posts() ) : ?>

    <!-- the loop -->
    <?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
       <div class="col-lg-4 col-md-4 col-sm-6 space-down-20">
        <a class="blog-post" href="<?php the_permalink(); ?>">
          <div class="thumbnail">
           <div class="image">
           <?php if ( has_post_thumbnail() ) {
         the_post_thumbnail( 'full', array( 'class' => 'featured-image' ) );
        } else { ?> <img src="home_header.jpg" class="featured-image"> <?php } ?>
           </div>
           <div class="caption">
            <h6 class="no-line"><?php the_time('F jS, Y');?></h6><br />
            <h3 class="no-line"><?php the_title();?></h3><br />
            <?php if(has_excerpt()){
                ?>
                <h5 class="text-muted"><strong><?php the_excerpt();?></strong></h5>
            <?php   
                }
            ?>
           </div>
        </div>
         </a>
       </div> 
       <?php endwhile; ?>
    <!-- end of the loop -->
</div>
<div class="row space-down-20">
<div class="col-sm-12">
    <!-- pagination here -->
    <?php
      if (function_exists(custom_pagination)) {
        custom_pagination($custom_query->max_num_pages,"",$paged);
      }
    ?>

  <?php wp_reset_postdata(); ?>

  <?php else:  ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
  <?php endif; ?>

0 个答案:

没有答案