简体   繁体   English

主页上最近博客的帖子数限制

[英]Recent Blog Posts Limit on Home Page

I'm having some problems setting up Number of posts to show on Home Page. 我在设置要显示在首页上的帖子数时遇到一些问题。 When I set the Number of Posts to show in theme options it reverts back to 3. I want to change the number of posts from 3 to 5. 当我设置要在主题选项中显示的帖子数时,它恢复为3。我想将帖子数从3更改为5。

Here is the code block on my home.php which I think needs a bit refinement. 这是我的home.php上的代码块,我认为需要进一步完善。

--> ->
  <?php $recent = new WP_Query("cat=".get_theme_mod('featured_top_left')."&showposts=".get_theme_mod('featured_top_left_num')); while($recent->have_posts()) : $recent->the_post();?> <?php if( get_post_meta($post->ID, "thumb", true) ): ?> <a href="<?php the_permalink() ?>" rel="bookmark"><img class="thumb" src="<?php bloginfo('template_directory'); ?>/tools/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", $single = true); ?>&amp;h=<?php echo get_theme_mod('featured_top_left_thumb_height'); ?>&amp;w=<?php echo get_theme_mod('featured_top_left_thumb_width'); ?>&amp;zc=1" alt="<?php the_title(); ?>" /></a> <?php else: ?> <?php endif; ?> 

According to Wordpress Manual : 根据Wordpress手册

showposts (int) - number of post to show per page. showposts(int)-每页显示的帖子数。 Deprecated as of Version 2.1 in favor of 'posts_per_page'. 从版本2.1开始不推荐使用,而推荐使用“ posts_per_page”。

So , if you're version is >2.1 you should edit the code and replace showposts with posts_per_page in the WP_Query . 因此,如果您的版本是> 2.1,则应编辑代码,并用posts_per_page中的WP_Query替换showposts

        <?php $recent = new WP_Query("cat=".get_theme_mod('featured_top_left')."&posts_per_page=".get_theme_mod('featured_top_left_num'));

UPDATED CODE. 更新的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM