【问题标题】:Exclude custom tags from the_tags从 the_tags 中排除自定义标签
【发布时间】:2012-09-12 14:35:05
【问题描述】:

我使用the_tags 来显示我的 Wordpress 网站的帖子标签,我使用以下代码:

<?php the_tags('',' • ',''); ?>

我需要从打印列表中排除/隐藏两个名为 featuredbilled 的标签。 这样做最有效的方法是什么?请只建议简单的解决方案,不要提出会减慢包含数千个标签和每小时页面浏览量的网站的心理查询。

【问题讨论】:

  • the_tags 不是打印出列表,而不是返回它吗?
  • 是的,我相信确实如此,我相应地改变了我的问题,干杯。

标签: php wordpress tags hide


【解决方案1】:

这是唯一更简单且不加载我正在考虑的页面的方法:

<?php
    $links = array();
    foreach(get_the_tags() as $this_tag) {
        if ($this_tag->name != "featured" && $this_tag->name != "billed"){
           $links[] = '<a href="'.get_tag_link($this_tag->term_id).'">'.$this_tag->name.'</a>';
        }
    }
    echo implode(' • ', $links);
?>

【讨论】:

  • 感谢您的回复。您能否详细说明您的答案,这比我使用的查询重得多吗?
  • 什么查询? the_tags('',' • ','')?,不,是一回事。
  • 更新:我刚刚测试了您的代码,但它不起作用。我的帖子上没有出现任何内容。您的代码中是否存在拼写错误或缺少某些内容?也没有返回错误...编辑:好的,让我试试新版本
  • +1,除了分隔符,你可以建立一个链接数组并加入它们
  • @soju 你能示范一下吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-21
  • 1970-01-01
  • 2013-09-17
  • 2016-01-30
  • 2011-07-08
  • 1970-01-01
相关资源
最近更新 更多