簡體   English   中英

如何在wordpress中僅x個帖子,無論是否存在粘性帖子

[英]SHow only x posts in wordpress, no matter if sticky posts exist or not

我正在嘗試將帖子輸出控制為三個,但Wordpress會添加粘性帖子,而忽略我的帖子限制。 因此,如果我有一個粘性帖子,則該頁面顯示4個帖子,而不是應有的三個。

我已經搜索並發現了類似的問題,但是代碼是如此不同,以致於無法在我的情況下正常工作。 全面披露:我不是php專家。

這是我的循環:

<?php  query_posts('showposts=3'); ?>
<?php  if (have_posts()) : while (have_posts()) : the_post(); ?>

<div class="news-item" id="post-<?php the_ID(); ?>">

<?php if ( has_post_thumbnail()) : ?>
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
        <span class="meta-date-group">
            <span class="meta-date-month"><?php the_time('M'); ?></span>
            <span class="meta-date-day"><?php the_time('j'); ?></span>
        </span>
        <?php the_post_thumbnail('square'); ?>
    </a>
<?php endif; ?>
<h4 class="hnews"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>

<div class="hexcerpt"><?php the_excerpt(); ?></div>
<a class="readmore" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >Read More</a>

</div><!--END news-item--> 

<?php endwhile; else: ?>

將此添加到您的查詢參數

"post__not_in"   => get_option("sticky_posts")

或者您可以按以下方式過濾循環中的信息:

if (!is_sticky())
  {
     // your code
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM