杜威分类法的分类规则

In the past we have shown you how to display subcategories on category pages in WordPress. Recently while working with Custom Taxonomies, we found a need to display child-taxonomies on parent-taxonomies archive page. After doing a bit of research, we didn’t find a single tutorial covering this issue. In this article, we will show you how to display a list of child taxonomies on taxonomies pages.

过去,我们向您展示了如何在WordPress的类别页面上显示子类别 。 最近,在使用自定义分类法时,我们发现有必要在父分类法档案页面上显示子分类法。 经过一些研究,我们没有找到涵盖此问题的单个教程。 在本文中,我们将向您展示如何在分类法页面上显示子分类法的列表。

Open up your custom taxonomy template file which may look like: taxonomy-{taxonomyname}.php and paste the following code where ever you want to display the list:

打开您的自定义分类模板文件,该文件可能类似于: taxonomy- {taxonomyname} .php ,并将以下代码粘贴到您想要显示列表的位置:


<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
if ($term->parent == 0) {
wp_list_categories('taxonomy=YOUR-TAXONOMY-NAME&depth=1&show_count=0
&title_li=&child_of=' . $term->term_id);
} else {
wp_list_categories('taxonomy=YOUR-TAXONOMY-NAME&show_count=0
&title_li=&child_of=' . $term->parent);
}
?>

Don’t forget to replace YOUR-TAXONOMY-NAME with the name of your taxonomy.

别忘了用您的分类名称替换YOUR-TAXONOMY-NAME。

Final Result:

最后结果:

Explanation:

说明:

We are using get_term_by to query the information of the current taxonomy by slug. For example if your taxonomy is called topics and you are on a page /topics/nutrition/ then $term variable will pull all the data related to the specific term page that you are on.

我们使用get_term_by来查询当前分类法的信息。 例如,如果您的分类法称为主题,而您在/ topics / nutrition /页面上,则$ term变量将提取与您所在的特定术语页面相关的所有数据。

In the project we were working on, the topics taxonomy was hierarchical just like categories. So we decided to run a conditional using $term->parent variable. This variable outputs the ID of the parent taxonomy. So if you are on the taxonomy nutrition which is the parent taxonomy, then $term->parent will echo 0. This is why we said if $term->parent == 0 then use wp_list_categories() function to display terms from our custom taxonomy that are child_of the term which page you are on. We accomplished this by using $term->term_id as the child_of variable.

在我们正在研究的项目中,分类法就像类别一样是分层的。 因此,我们决定使用$ term-> parent变量运行条件。 此变量输出父分类法的ID。 因此,如果您使用的是分类法营养(即父分类法),则$ term-> parent将回显0。这就是为什么我们说如果$ term-> parent == 0则使用wp_list_categories()函数显示自定义项中的术语属于您所在页面的术语child_的分类法。 我们通过使用$ term-> term_id作为child_of变量来完成此操作。

Now if you go to the child taxonomy page, it would have been blank because the $term->parent would no longer equals to 0. On a child taxonomy page, $term->parent outputs the ID of the parent category. So we ran an else statement using the same wp_list_categories() function except we changed $term->term_id to $term->parent.

现在,如果转到子分类页面,则该页面将为空白,因为$ term-> parent不再等于0。在子分类页面上,$ term-> parent输出父类别的ID。 因此,我们使用相同的wp_list_categories()函数运行了else语句,除了将$ term-> term_id更改为$ term-> parent。

There you have it. We hope that this helps everyone who was looking for a solution.

你有它。 我们希望这对寻求解决方案的所有人有所帮助。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-display-child-taxonomy-on-parent-taxonomys-archive-page/

杜威分类法的分类规则

杜威分类法的分类规则_如何在父分类法的存档页面上显示子分类法相关推荐

  1. sklearn保存svm分类模型_【菜菜的sklearn】07 支持向量机(上)

    小伙伴们大家好~o( ̄▽ ̄)ブ,我是菜菜,这里是我的sklearn课堂第7期,今天分享的内容是支持向量机(上),下周还有下篇哦~ 我的开发环境是Jupyter lab,所用的库和版本大家参考:Pyth ...

  2. python网页查询然后返回结果_使用pythondjang在html页面上显示查询到的API结果

    我目前正在使用django webframework创建一个python应用程序,它允许用户查询外部API来获取有关食物营养(例如卡路里.脂肪)的信息.目前,当用户在网页上的搜索栏中输入食物时,API ...

  3. python爬虫今日头条街拍美图开发背景_分析Ajax请求并抓取今日头条街拍美图:爬取详情页的url与实际页面上显示不符...

    from urllib.parse import urlencode import re from requests.exceptions import RequestException from b ...

  4. java商城购物车商品sku变化_在Woocommerce 3中的购物车和结帐页面上显示SKU

    你需要做一些模板覆盖 . Cart 如果 my_theme/woocommerce/cart/cart.php 尚未存在,请将 plugins/woocommerce/templates/cart/c ...

  5. word单元格斜网格_如何在Word中的所有表上显示和隐藏单元格网格线

    word单元格斜网格 By default, when you create a new table, all the cells have black borders that print with ...

  6. java vo命名规则_阿里java开发手册中命名规约解读之DO/BO/DTO/VO/AO

    前言 在阅读<阿里巴巴Java开发手册>时,看到命名规则中有这样一条 虽然知道这些是根据Java对象的角色所分配名称的后缀,但是没有弄清楚分别是什么意思,日常开发中也没有使用到. 网上查找 ...

  7. fomo规则_如何在WordPress网站上使用FOMO来增加转化次数

    fomo规则 You may have heard of FOMO and social proof notifications when reading about latest marketing ...

  8. 客栈管理系统java源代码_源码客栈项目源码分类规则

    源码客栈团队截至目前已经为Java相关课程设计.实训.毕业设计开发了很多对应的源码,为了整理这些源码我们制定了如下的分类规则,方便大家迅速定位找到合适自己的源码. 星星等级:✩✩星星数量表示难易程度, ...

  9. c语言取余规则_这是我的C语言入门笔记

    点击上方"C语言中文社区",选择"设为星标★" 技术干货第一时间送达! 来自:大鱼机器人 精彩回顾: [万字长文]C语言高效编程与代码优化,建议收藏![推荐] ...

最新文章

  1. php 类 单例,PHP里的单例类写法实例
  2. C语言经典例80-猴子分桃
  3. Matlab xcorr函数详解
  4. java jedis sadd_Java实现Redis的集合(set)命令操作
  5. 拉美光伏新兴市场热潮将至
  6. Educational Codeforces Round 81 (Rated for Div. 2) F.Good Contest \ 洛谷 划艇 组合 计数dp
  7. 2012.2.9日晚亚马逊的一个错误链接截图
  8. 开源框架 Apache Struts 2漏洞的 PoC 已公开
  9. Assembly Manifest 通俗简易手册
  10. Excel控件 Spire.XLS系列教程(2):C# 设置现有 Excel 图表的数据标签样式
  11. 登录亿邮网关windows脚本
  12. java 图片转换 gif转jpg
  13. accuracy(准确率), precision(精密度), recall(召回率), specificity(特异性), and F1-score(F1分数):分别是什么意思?
  14. vue 加载720全景图
  15. Cadence PSpice 补充1:脉冲信号源的详细介绍与使用方法图文演示
  16. 安装Windows服务报错:未能加载文件或程序集
  17. 人工智能基础——搜索算法
  18. 人物的喜怒哀乐怎么画?动漫人物表情怎么画?
  19. idea中添加类、方法注释,快捷键设置
  20. 梁辉老师.狼性营销实战训练专家

热门文章

  1. 小蚁智能摄像机服务器故障,小蚁智能摄像机连接Wifi失败密码错误该怎么办?...
  2. 安卓开发 科学计算器
  3. 单片机c51语言定义bool类型,C51单片机数据类型的具体定义及应用
  4. 【Verilog - 组合逻辑 - 基础3】4. 与或门-1
  5. Ubuntu虚拟机使用NAT连接 然后无法上网的情况
  6. 简单无脑,上手即用 - 手把手教你使用 智能红外温度传感器代码以及依赖的 gitee 库
  7. 目标检测跟踪算法--传统方法
  8. td内容过长,其他显示省略号
  9. CTFHub-Web-文件上传
  10. 汽车制动系统的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告