当前位置: 首页 > news >正文

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

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

http://www.lryc.cn/news/255203.html

相关文章:

  • C#里面的泛型(T),泛型类,泛型方法,泛型接口等简单解释
  • C语言——指针(五)
  • 文章解读与仿真程序复现思路——中国电机工程学报EI\CSCD\北大核心《考虑气电联合需求响应的气电综合能源配网系统协调优化运行》
  • PostgreSQL 主键和唯一键的区别
  • 删除表格中的所有绘图
  • Linux卸载Nginx
  • Qt之QGraphicsView —— 笔记1:绘制简单图元(附完整源码)
  • SpringIoC原理
  • 如何对售后服务的全流程进行精细化的管理?
  • SAP UI5 walkthrough step2 Bootstrap
  • Gemini:定义下一代人工智能的里程碑
  • 一些系统日常运维命令和语句
  • 微信小程序uni.chooseImage()无效解决方案
  • Rust深入浅出:编程的深邃大海中的奇妙冒险
  • go-zero开发入门-API网关开发示例
  • TCP一对一通信
  • laravel DB::connection 报错 Database connection [{$name}] not configured
  • 快捷支付是什么?快捷支付好申请吗?
  • 如何在Spring Boot中集成RabbitMQ
  • 【Spring Boot 源码学习】ApplicationContextInitializer 详解
  • 软考2018下午第六题改编逻辑(状态模式)
  • 基于深度学习的典型目标跟踪算法
  • docker搭建nginx实现负载均衡
  • Android蓝牙协议栈fluoride(二) - 软件框架
  • IDEA中的Postman!
  • el-tooltip (element-plus)修改长度
  • Verilog学习 | 用initial语句写出固定的波形
  • 使用arcpy移除遥感影像云层
  • 编程应用实例,商超进销存管理系统软件,支持扫描条形码也可以自编码
  • 第二证券:十字星买入法?