繁体   English   中英

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

[英]Recent Blog Posts Limit on Home Page

我在设置要显示在首页上的帖子数时遇到一些问题。 当我设置要在主题选项中显示的帖子数时,它恢复为3。我想将帖子数从3更改为5。

这是我的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; ?> 

根据Wordpress手册

showposts(int)-每页显示的帖子数。 从版本2.1开始不推荐使用,而推荐使用“ posts_per_page”。

因此,如果您的版本是> 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'));

更新的代码。

暂无
暂无

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

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