在Wordpress主页上设置不同数量的帖子

时间:2017-03-08 12:12:21

标签: php wordpress posts

我创建了一个Wordpress博客,并将每页的默认帖子数设置为6。 现在,我想在我的主页上只显示4个帖子。所以我创建了以下页面模板,但我找不到将帖子数量限制为4的方法。 有什么想法吗?

    <?php /* Template Name: HP Blog */ ?>
<?php get_header(); ?>
<div id="main" class="main">
<div class="container">
<section id="content" class="content">
<?php do_action('cpotheme_before_content'); ?>
<?php if(have_posts()) while(have_posts()): the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="page-content">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
<?php $query = new WP_Query("post_type=post&paged=".cpotheme_current_page()."&posts_per_page=".get_option('posts_per_page')); ?>
<?php if($query->posts): ?>
<?php cpotheme_grid($query->posts, 'element', 'blog', cpotheme_get_option('blog_columns'), array('class' => 'column-narrow')); ?>
<div class="homepageposts"><a style="width:80%;" class="post-readmore button" href="/συμβουλές/">Δείτε όλα τα άρθρα</a></div>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php do_action('cpotheme_after_content'); ?>
</section>
<?php get_sidebar(); ?>
<div class="clear"></div>
</div>
</div>
<?php get_footer(); ?>

2 个答案:

答案 0 :(得分:2)

只需替换此代码

query = new WP_Query("post_type=post&paged=".cpotheme_current_page()."&posts_per_page=".get_option('posts_per_page'));

query = new WP_Query("post_type=post&paged=".cpotheme_current_page()."&posts_per_page="4");

答案 1 :(得分:0)

备用解决方案和简单的解决方案可以通过后端/管理面板进行设置。

  

转到信息中心&gt;设置&gt;阅读,然后将博客页面最多显示为   4。

希望这有帮助!