如何在 Elementor 中显示与特定帖子相关的标签?

问题描述 投票:0回答:1

我使用自定义帖子类型 UI 创建了自定义标签分类。对于每个帖子,我想显示与该特定帖子相关的标签,而不是所有标签的列表。关于如何执行此操作有什么建议吗?我正在 Wordpress 上使用 Elementor Pro。

我已经找到了一种过滤 Elementor Tags Cloud 小部件的方法,以便它只显示与帖子关联的标签,但尚未找到实现此目的的方法。

预先感谢您的任何建议。

tags custom-post-type elementor
1个回答
0
投票

您可以复制下面的代码在function.php(外观->主题文件编辑器)中创建一个短代码,或者使用WP Code插件更容易,下面的代码只会根据帖子显示标签。

function post_tags_func()
{
  $tags = get_the_tags();
  $return .= '<div class="post-tags">';
  if ($tags) {
    foreach ($tags as $tag) {
      $return .= '<a href="' . get_category_link($tag->term_id) . '">#' . $tag->name . '</a>';
    }
  }
  $return .= '</div>';
  return $return;
}

add_shortcode('post_tags', 'post_tags_func');
© www.soinside.com 2019 - 2024. All rights reserved.