WordPress禁止显示指定类别的文章

本站优惠券栏目展示的都是具有优惠券的淘宝热销商品,如果商品正合您意不妨先领个优惠券在去下单,您每一次领取优惠券在下单老马都会给我一点点小费,就权当对小弟的支持可好?如果栏目里没有中意的商品也别急,我还专门为您提供了一个京东淘宝优惠券网站,点击右边这个链接可以直接进入👉https://quan.yumus.cn,下单前可以在这个网站搜索一下看有没有您需要的商品,所有的交易都是在淘宝或京东完成您无需担心售后服务和交易安全,小弟在此恳请大家多多支持。

使用wordpress禁止输出指定类别的文章可以给get_posts()函数传个数组参数,如下:

<div class="widget" id="diary1">
<h3>随机呈现</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>

其中:

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

键名numberposts表示取出的文章数,category表示要显示的文章的类别ID,负数代表不显示,以字符串的形式用逗号隔开,orderby这里表示随机取出文章。去掉了php类别的文章显示,因为下面有了一个“php专栏”,避免重复。

get_posts()函数完整的参数列表:

<?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 );
?>