获取与类别相关的标记

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取与类别相关的标记相关的知识,希望对你有一定的参考价值。

  1. //to go in functions.php
  2.  
  3. function get_category_tags($args) {
  4. global $wpdb;
  5. $tags = $wpdb->get_results
  6. ("
  7. SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, null as tag_link
  8. FROM
  9. wp_posts as p1
  10. LEFT JOIN wp_term_relationships as r1 ON p1.ID = r1.object_ID
  11. LEFT JOIN wp_term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
  12. LEFT JOIN wp_terms as terms1 ON t1.term_id = terms1.term_id,
  13.  
  14. wp_posts as p2
  15. LEFT JOIN wp_term_relationships as r2 ON p2.ID = r2.object_ID
  16. LEFT JOIN wp_term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id
  17. LEFT JOIN wp_terms as terms2 ON t2.term_id = terms2.term_id
  18. WHERE
  19. t1.taxonomy = 'category' AND p1.post_status = 'publish' AND terms1.term_id IN (".$args['categories'].") AND
  20. t2.taxonomy = 'post_tag' AND p2.post_status = 'publish'
  21. AND p1.ID = p2.ID
  22. ORDER by tag_name
  23. ");
  24. $count = 0;
  25. foreach ($tags as $tag) {
  26. $tags[$count]->tag_link = get_tag_link($tag->tag_id);
  27. $count++;
  28. }
  29. return $tags;
  30. }
  31.  
  32. // template tag
  33.  
  34. $args = array('categories' => '12,13,14');
  35. $tags = get_category_tags($args);

以上是关于获取与类别相关的标记的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 WordNet 或与 wordnet 相关来实现基于类别的文本标记?

text WORDPRESS:从类别中获取所有标记

如何获取类别、文章和子类别及其文章?

基于实体关系的核心数据获取

Wordpress - 与帖子相关的类别列表

获取总类别树(所有类别及其子类别的列表)与根据需要获取每个分支?