在自定义博客页面模板中添加分页

我正在为博客使用自定义页面(page-allblogs.php)。我没有写这个页面中的所有代码,因为我想写干净的代码。所以这个页面有以下代码:


<?php get_header();?>


<?php get_template_part('navigation'); ?>


<?php get_template_part('blogslist'); ?>


<?php get_footer();?>

博客列表的主要代码在页面 bloglist.php


<div class="col-md-9">


        <!-- INDIVIDUAL BLOG ITEM LIST -->


          <?php

            $args = array(

            'posts_per_page' => 2,

            'post_type'     => 'blog', 

            'orderby'       => 'date',

            'order'         => 'DESC' 

            );


            $loop = new WP_Query($args);

            if($loop->have_posts()) {


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

          ?>

          <div class="blog-item">


          <div class="blog-item__top">

            <div class="blog-item__image">

              <a href="<?php the_permalink();?>">

                <?php $image = get_field('image');

                if( !empty($image) ): ?>


                  <img src="<?php echo $image['url']; ?>" class="img-responsive" alt="<?php echo $image['alt']; ?>" />


                <?php endif; ?>

              </a>

            </div>


            <div class="blog-item__detail">

              <ul>

                <li><a href="#"><i class="fa fa-calendar" aria-hidden="true"></i><?php the_time('M j, Y');?></a></li>

                <li><a href="#"><i class="fa fa-thumbs-up" aria-hidden="true"></i>201 LIKES</a></li>

                <li><a href="#"><i class="fa fa-comment" aria-hidden="true"></i>15 COMMENTS</a></li>

              </ul>

            </div>

          </div>


我正在使用 wpbeginner 的分页代码,我已经把它放在了functions.php 中。


慕村225694
浏览 161回答 1
1回答

倚天杖

我在 $args 中错过了这个。$paged&nbsp;=&nbsp;get_query_var(&nbsp;'paged'&nbsp;)&nbsp;?&nbsp;absint(&nbsp;get_query_var(&nbsp;'paged'&nbsp;)&nbsp;)&nbsp;:&nbsp;1;
打开App,查看更多内容
随时随地看视频慕课网APP