簡體   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