【问题标题】:How to set your own $args in Wordpress default-tags?如何在 Wordpress 默认标签中设置自己的 $args?
【发布时间】:2015-08-01 12:24:10
【问题描述】:

我发现了一个问题,我的标签包含数字。但我不希望标签云显示它们。如何排除标签,但解决方案是添加过滤器。 我的目标是在调用 tags_cloud 之前设置 $args。 如何修改 default-widgets.php 或为此创建解决方法?

wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
        'taxonomy' => $current_taxonomy
    ) ) );

你能揭开它的神秘面纱吗?如何正确添加我自己的 $args 属性? $current_taxonomy 在哪里创建?

【问题讨论】:

    标签: php wordpress tags widget


    【解决方案1】:

    wp_tag_cloud() 已经接受taxonomy(作为字符串或数组)和exclude(作为要排除的term_ids 的逗号分隔列表)的参数:

    $args = array(
        'taxonomy' => 'some_registered_taxonomy',
        'exclude' => '3,65,2',
    );
    wp_tag_cloud( $args );
    

    更多信息in the Codex

    【讨论】:

    • 我的情况是,我想设置正则表达式来排除包含数字的标签。编辑 default-widgets.php 是一种好习惯,还是更好地在我的主题子的 functions.php 中创建过滤器来为 wp_tag_cloud() 设置参数。显示的文件位于 wp-includes/default-widgets.php。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多