Notice: Trying to access array offset on value of type bool in /www/wwwroot/weimahe.com/wp-content/advanced-cache.php on line 472

Notice: Trying to access array offset on value of type bool in /www/wwwroot/weimahe.com/wp-content/advanced-cache.php on line 472
WordPress判断文章是否属于某分类标签:in_category - 微码盒
!
也想出现在这里? 联系我们
广告位

WordPress判断文章是否属于某分类标签:in_category

WordPress模板标签in_category用于判断文章是否属于某分类,该函数只能在The Loop主循环中使用,如果有明确指定文章ID,那么可以在任何地方使用。

in_category( int|string|array $category, int|object $post = null )

函数参数

$category

整数/字符串/数组,默认为空

分类的ID,可以是多个

$post

整数/对象,默认值:当前文章ID

如果在主循环中使用,可以不指定该参数的值,默认取当前文章的ID,在主循环之外使用,需要明确指定文章ID

函数使用示例

<?php
if( in_category( array(2,6,8), $post-&gt;ID )) {
echo 'yes';
} else {
echo 'no';
}
?>

扩展阅读

in_category()函数位于:wp-includes/category-template.php

相关函数:

  • the_category()
  • the_category_rss()
  • single_cat_title()
  • category_description()
  • wp_dropdown_categories()
  • wp_list_categories()
  • get_category_parents()
  • get_the_category()
  • get_category_link()

给TA打赏
共{{data.count}}人
人已打赏
WordPress教程

WordPress作者名称标签:the_author

2021-4-9 11:29:04

WordPress教程

WordPress根据分类ID获取分类链接标签:get_category_link

2021-4-9 23:32:14

下载说明

  • 1、微码盒所提供的压缩包若无特别说明,解压密码均为weimahe.com
  • 2、下载后文件若为压缩包格式,请安装7Z软件或者其它压缩软件进行解压;
  • 3、文件比较大的时候,建议使用下载工具进行下载,浏览器下载有时候会自动中断,导致下载错误;
  • 4、资源可能会由于内容问题被和谐,导致下载链接不可用,遇到此问题,请到文章页面进行反馈,以便微码盒及时进行更新;
  • 5、其他下载问题请自行搜索教程,这里不一一讲解。

站长声明

本站大部分下载资源收集于网络,只做学习和交流使用,版权归原作者所有;若为付费资源,请在下载后24小时之内自觉删除;若作商业用途,请到原网站购买;由于未及时购买和付费发生的侵权行为,与本站无关。本站发布的内容若侵犯到您的权益,请联系本站删除,我们将及时处理!
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索