【问题标题】:remove category archive titles删除类别存档标题
【发布时间】:2020-06-18 14:03:49
【问题描述】:

如何让它检查子类别或子类别?

function wporg_remove_category_title( $title ) {
        if ( is_category() ) {
            $title = single_cat_title( '', false );
        }
        return $title;
    }
    add_filter( 'remove_the_archive_title', 'wporg_remove_category_title' );

【问题讨论】:

标签: wordpress archive


【解决方案1】:

我不确定您到底想达到什么目标,因为您的标题似乎与您的问题内容不同。但我想我可以指引你一个方向。


如果您在archive.php 主题文件中使用the_archive_title(),它将始终显示Archive: Post Type Name。如果想去掉标题前的Archive:,可以使用:

single_cat_title();

这只会显示档案标题。


要检查一个类别是否有子类别,您可以使用 wordpress 功能get_term_children()

https://developer.wordpress.org/reference/functions/get_term_children/

这将为您提供一个包含所有学期子 ID 的数组。因此,如果要检查类别术语是否有子项,可以将子项保存在数组中并检查该数组是否为空。

$children = get_term_children($term_id, $taxonomy);

if( empty( $children ) ) {
    // do something if there are no children
} else {
    // do something if there are children
}

【讨论】:

  • “我不确定你到底想达到什么目的......” 不鼓励回答不清楚的问题(比如这个) - 请参阅 Answer问得好问题 How to answer。在这种情况下,您可以在问题中添加评论以要求提供更多信息以澄清问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多