【问题标题】:Excluding specific multiple tags in the tag list in WordPress在 WordPress 的标签列表中排除特定的多个标签
【发布时间】:2016-09-25 10:39:18
【问题描述】:

我想从以下脚本的标签列表中排除 2 个标签:

$tags = get_tags();
$html = '<ul>';
foreach ( $tags as $tag ) {
if($tag->slug != "test1"){
$tag_link = get_tag_link( $tag->term_id );
$html .= "<li><a href='{$tag_link}' class='{$tag->slug}'>";
$html .= "{$tag->name}</a></li>";
}}
$html .= '</ul>';
echo $html;

test1 标记外,脚本正常工作。 如何编辑代码以排除另一个名为 test2 的标签?

【问题讨论】:

    标签: php wordpress tags


    【解决方案1】:

    根据DOCS

    'exclude' 默认为空字符串。逗号或空格分隔 要从返回数组中排除的术语 ID 字符串。如果“包括”是 非空,“排除”被忽略。

    您需要将1,2 的标签ID 更改为test1test2

    $args = array('exclude' => '1,2' );
    $tags = get_tags($args);
    // .... Rest of your code goes here
    

    不要忘记删除 if 检查 if($tag-&gt;slug != "test1"){,因为在 $args 中使用 exclude 将无用 :)

    【讨论】:

    • 不要忘记然后离开 if($tag->slug != "test1"){ 部分,因为它不再需要了
    猜你喜欢
    • 2012-04-15
    • 2018-09-23
    • 2015-10-24
    • 1970-01-01
    • 2015-02-20
    • 2015-07-30
    • 2013-07-30
    • 2020-07-22
    • 1970-01-01
    相关资源
    最近更新 更多