嗨,我的 Wordpress 主题不支持 img 分页.如何在WordPress中添加自定义分页


Hi my Wordpress theme not supportimg pagination.How can i add custom pagination in wordpress?

我只想在我的博客页面中显示 5 篇文章。有没有办法解决这个问题?

嗨,

nikita 分页是 wordpress 的默认属性。参考 WordPress Codex因此,请从模板文件(索引.php,类别.php)中删除query_posts部分。

    <?php 
// query to set the posts per page to 5
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 5, 'paged' => $paged );
query_posts($args); ?>

并将主页和类别页面的查询添加回主题的功能.php文件:

function my_post_queries( $query ) {
  // do not alter the query on wp-admin pages and only alter it if it's the main query
  if (!is_admin() && $query->is_main_query()){
    // alter the query for the home and category pages 
    if(is_home()){
      $query->set('posts_per_page', 5);
    }
    if(is_category()){
      $query->set('posts_per_page', 5);
    }
  }
}
add_action( 'pre_get_posts', 'my_post_queries' );

也许你的问题会解决...