Wordpress home.php 中的分页

分页在 Wordpress 博客中不起作用。我已经跟踪到 home.php 的具体负责文件。


原始博客页面可以正常显示帖子(一次 10 个),但是如上所述分页不起作用。


<?php

/**

Category Page

*/

get_header(); ?>

<div class="container-fluid blogs post-section" id="blogs">

<div class="container">

<div class="row">

<div class="col-sm-12 col-md-9 col-lg-8">

<?php echo category_description( $category_id ); ?> 


<div class="category-posts">


<?php


$args = array(

    "post_type" => "post",

    "post_status" => "publish",

    "posts_per_page" => "10",

    "orderby" => "date",

    "order" => "DESC"

);

$query = new WP_Query($args);


if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>

<div class="col-sm-12">

<div class="inner-post">

<?php if ( has_post_thumbnail() ) { ?><div class="thumbnail col-sm-4" style="background:none!important;"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a></div><?php } ?>

<div class="abso custom_abso col-sm-8"><div class="inner-box">

<div class="date">

<?php 

$archive_year  = get_the_time('Y'); 

$archive_month = get_the_time('M'); 

$archive_day   = get_the_time('d'); 

?>

  <span class="month"><?php echo $archive_month; ?></span> <span class="day"><?php echo $archive_day; ?>,</span><span class="year"><?php echo $archive_year; ?></span>

</div>

<h2 style="margin-top:0;"><a  href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

<?php the_excerpt(); ?>

</div>

</div>

</div>

<p><a href="<?php the_permalink(); ?>" class="readmores">Read More <i class="fa fa-caret-right" aria-hidden="true"></i>

</a></p>

</div>

<?php endwhile; endif;

 ?></div>

<div class="pagination text-center">

<?php the_posts_pagination( array( 'mid_size' => 2 ) ); ?>

</div>

<?php wp_reset_query(); ?>

</div>

<?php get_sidebar(); ?>

</div></div></div>

<?php get_footer(); ?>


这很有效,因为分页按钮可以工作,但是,每页只显示一篇文章:

http://img.mukewang.com/61e135280001743922621182.jpg

关于如何每页显示 10 个帖子的任何建议?


大话西游666
浏览 159回答 1
1回答

白猪掌柜的

请添加以下参数“分页”。它设置分页查询变量。分页是根据这个参数工作的。&nbsp;'paged'&nbsp;=>&nbsp;(&nbsp;get_query_var('paged')&nbsp;?&nbsp;get_query_var('paged')&nbsp;:&nbsp;1)到$args.
打开App,查看更多内容
随时随地看视频慕课网APP