wordpress
2010-05-19 215 views 1 likes 
1

我想知道如何排除Wordpress中的帖子。 例如我有一個字符串排除Wordpress中的帖子

$exclude_ids (= "4,5,6") or (="-4,-5,-6") 

我想阻止這些帖子出現。我會怎麼做?

我已經嘗試過:

query_posts('p=' . $exclude_ids); 

,但沒有真正的工作了,我並沒有真正找到有關對谷歌這個話題的任何信息。

乾杯

回答

2

下面是the docs相關信息:

'post__not_in'=>陣列(6,2,8) - 排除,可以指定後 id,而不是檢索

2

這是在食品:http://codex.wordpress.org/Function_Reference/query_posts

使用post__not_in,類似於:query_posts(array('post__not_in'=>'1,2,3'))

-1

理想的解決方案是創建一個類別,將這些帖子添加到該類別中,然後排除該類別。但是如果你真的想單獨發佈帖子,可以這樣做:

<?php if (have_posts()) : 
    while (have_posts()) : the_post(); 
    if ($post->ID == '179' || $post->ID == '180' || $post->ID == '181') continue;?> 
<?php the_content();?> 
<?php endwhile;endif;?> 

只需在循環中使用if語句即可。繼續將跳過任何列出的帖子的迭代。

來源:http://www.sandboxdev.com/blog/wordpress/180/exclude-single-post/

+0

,因爲你要拉更多的數據比你想顯示這是不好的。儘管WordPress的開銷很高,但不要讓它比努力完成你想完成的工作更難。 – Gipetto 2010-05-20 05:18:00

相關問題