【问题标题】:Cannot retrieve all tags from custom loop without duplicates无法从没有重复的自定义循环中检索所有标签
【发布时间】:2019-10-30 15:12:48
【问题描述】:

我必须从自定义标签列表中检索所有不重复的标签,所以我遵循了以下给出的解决方案:

How to remove ducplicate tags from custom tag list?

我尝试自定义解决方案中给出的PHP代码如下,只得到foreach块返回的一个标签ID:

if(is_category()):
 $category = get_query_var('cat');
  $categories = get_category($category);
 endif;
 $tagIDs = array();
 query_posts('category_name='.$categories->slug);
 if(have_posts()) : while(have_posts()) : the_post();
 $tags = get_the_tags();
 if($tags):
  foreach($tags as $tag){
   if(!in_array($tag->term_id, $tagIDs)):
    $tagIDs[] = $tag->term_id;
    $tagNames[$tag->term_id] = $tag->name;
   endif;
  }
  endif;
 endwhile; endif;
 wp_reset_postdata();
 echo '<ul>';
 foreach($tagIDs as $tagID):
  echo '<li><a href="'.get_tag_link($tagID).'">'.$tagNames[$tagID].'</a></li>';
 endforeach;
 echo '</ul>';

我必须检索所有没有重复的标签 slug。我怎样才能做到这一点?

【问题讨论】:

  • 那么,这些代码有没有返回任何东西? $tagIDs 是否包含所有标签 ID?
  • $tagID 只返回一个 ID,即 9。

标签: php wordpress tags custom-tags


【解决方案1】:

更改 paginate_links() 的设置方式可解决此问题。

【讨论】:

    猜你喜欢
    • 2020-09-25
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 2020-08-27
    • 1970-01-01
    • 1970-01-01
    • 2015-06-12
    • 2018-11-05
    相关资源
    最近更新 更多