百度
360搜索
搜狗搜索

wordpress get_posts函数的使用方法 禁止输出指定类别的文章详细介绍

本文向大家介绍wordpress使用get_posts函数功能禁止输出指定类别文章的方法,大家可以参考一下

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

代码如下:

<div class="widget" id="diary1">

<h3>随机呈现</h3>

<ul>

<?

$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这里表示随机取出文章。

效果如小谈博客首页右侧&ldquo;随机呈现”效果,去掉了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' => 'pos t',

'post_mime_type' => '',

'post_parent' => '',

'post_status' => ' publish',

'suppress_filters' => true );

?>

本文标题: wordpress get_posts函数的使用方法 禁止输出指定类别的文章 ,

阅读更多 >>>  随机数生成c语言,C语言如何编程产生随机数?

文章数据信息:

本文主要探讨:"wordpress get_posts函数的使用方法 禁止输出指定类别的文章", 浏览人数已经达到63次, 首屏加载时间:0.482 秒。