欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

wordpress get_posts函數(shù)的使用方法 禁止輸出指定類別的文章

  發(fā)布時(shí)間:2013-11-13 15:48:08   作者:佚名   我要評(píng)論
本文向大家介紹wordpress使用get_posts函數(shù)功能禁止輸出指定類別文章的方法,大家可以參考一下
使用wordpress禁止輸出指定類別的文章可以給get_posts()函數(shù)傳個(gè)數(shù)組參數(shù),如下:

復(fù)制代碼
代碼如下:

<div class="widget" id="diary1">
<h3>隨機(jī)呈現(xiàn)</h3>
<ul>
<?php
$args=array(
'numberposts'=>16,
'category'=>'-9,-12',
'orderby'=>'rand'
);
$rand_posts = get_posts($args);
foreach( $rand_posts as $post ) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
</div>

其中:

復(fù)制代碼
代碼如下:

$args=array(
'numberposts'=>16,
'category'=>'-9,-12',
'orderby'=>'rand'
);

鍵名numberposts表示取出的文章數(shù),category表示要顯示的文章的類別ID,負(fù)數(shù)代表不顯示,以字符串的形式用逗號(hào)隔開,orderby這里表示隨機(jī)取出文章。
效果如小談博客首頁右側(cè)“隨機(jī)呈現(xiàn)”效果,去掉了php類別的文章顯示,因?yàn)橄旅嬗辛艘粋€(gè)“php專欄”,避免重復(fù)。
get_posts()函數(shù)完整的參數(shù)列表:

復(fù)制代碼
代碼如下:

<?php $args = array(
'posts_per_page' => 5,
'numberposts' => 5,
'offset' => 0,
'category' => '',
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true );
?>

相關(guān)文章

最新評(píng)論