分页在wordpress页面上不起作用

时间:2016-01-06 21:25:49

标签: php wordpress pagination

我制作了一个显示帖子的页面但是没有出现分页(1,2,3等等)

这是代码:

<div class="browse-content">
    <div class="container">
        <h2><?php echo wp_count_posts()->publish; ?> Movies Found</h2>
        <section>
            <div class="row">
                <ul>    
                <?php
                    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
                    $args = array(
                      'posts_per_page' => 3,
                      'paged'          => $paged
                    );

                    $the_query = new WP_Query( $args ); 
                ?>
                    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
                        <?php  include '_includes/items/item_2.php';?>
                <?php endwhile; wp_reset_postdata();?>
                </ul>
            </div>
        </section>
        <div class="pagination"><?php novavideo_theme_pagination(); ?></div><!-- .pagination -->
        </div>
    </div>
</div>    

我搜索了所有地方,但我没有找到答案......

有人可以帮助我吗?

4 个答案:

答案 0 :(得分:0)

function novavideo_theme_pagination($pages = '', $range = 4){  
 $showitems = ($range * 2)+1;  

 global $paged;
 if(empty($paged)) $paged = 1;

 if($pages == '')
 {
     global $wp_query;
     $pages = $wp_query->max_num_pages;
     if(!$pages)
     {
         $pages = 1;
     }
 }   

 if(1 != $pages)
 {
     echo "<div class=\"pagination\"><ul><li><span>Page ".$paged." of ".$pages."</span></li>";

     if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link(1)."'>&laquo; First</a></li>";
     if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a></li>";

     for ($i=1; $i <= $pages; $i++)
     {
         if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
         {
             echo ($paged == $i)? "<li><span class=\"current\">".$i."</span></li>":"<li><a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a></li>";
         }
     }

     if ($paged < $pages && $showitems < $pages) echo "<li><a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a></li>";  
     if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($pages)."'>Last &raquo;</a></li>";
     echo "</ul></div>\n";
 }

}

这是代码

答案 1 :(得分:0)

将这两行添加到主题的function.php文件中,一切都将重新开始工作:

add_filter(‘redirect_canonical’,’custom_disable_redirect_canonical’);

function custom_disable_redirect_canonical($redirect_url) {if (is_paged() && is_singular()) $redirect_url = false; return $redirect_url; }

答案 2 :(得分:-1)

public function updateEmployeePayroll() {
    $this->db->where('emp_id', $this->emp_id);
    $query = $this->db->update('tbl_payroll', $this);
    return $query;
}

答案 3 :(得分:-2)

我认为更好的方法是使用this plugin