2012-03-30 159 views
0

此代码是95%的工作,但我需要一些帮助最后一部分。我试图从Wordpress中获取所有的自定义分类和分类术语,并将它们显示在无序列表中。这里是我的代码:WordPress的:获取自定义分类和分类术语

$args=array('public' => true, '_builtin' => false); 
     $output = 'names'; 
     $operator = 'and'; 
     $taxonomies=get_taxonomies($args,$output,$operator); 
     if ($taxonomies) { 
      foreach ($taxonomies as $taxonomy) { 
      echo '<a>'. $taxonomy. '</a>'; 
      $terms = get_terms("color"); 
      $count = count($terms); 
      if ($count > 0){ 
       echo '<ul>'; 
        foreach ($terms as $term) { 
         echo "<li>" . $term->name . "</li>"; 
        } 
       echo "</ul>"; 
      } 
      } 
     } 

的问题是在第8行的地方读取$terms = get_terms("color");。我将其作为测试代码的手段,但问题在于Wordpress现在显示了每种分类标准的分类“颜色”中的术语。

我该如何修改此代码,以便Wordpress显示每个分类标准时,它还会显示该分类的相应术语列表?

+0

作为一个PHP新手,我想这会工作'$项= get_terms($分类);' – colindunn 2012-03-30 17:12:55

回答

0

$terms = get_terms($taxonomy->name);

+0

我试过了,还有'$学期= get_terms(get_query_var('分类学'));'。没有骰子:( – colindunn 2012-03-30 17:51:26

+0

oo没有看到输出名称试试'$ terms = get_terms($ taxonomy ['name'])' – 2012-03-31 21:22:46

1

colindunnn,感谢您的代码伴侣。试图做类似的事情时,它帮助了很多... 我想显示所有分类:

 
Taxonomy1 
-Terms1a 
-Terms1b 
-etc 

Taxonomy2 
-Terms2a 
-Terms2b 
-etc 

这里是代码......如果有人需要他们。 ?

<?php $args=array('public' => true, '_builtin' => false); 
$output = 'names'; 
$operator = 'and'; 
$taxonomies=get_taxonomies($args,$output,$operator); 
if ($taxonomies) { 
    foreach ($taxonomies as $taxonomy) { 
     echo '<a>'. $taxonomy. '</a>'; 
     $terms = get_terms($taxonomy); 
     $count = count($terms); 
     if ($count > 0){ 
      echo '<ul>'; 
      foreach ($terms as $term) { 
       $termlinks= get_term_link($term,$taxonomy); 
       ?> <a href="<?php echo $termlinks; ?>"> 
       <?php echo "<li>" . $term->name . "</li>"; ?></a><?php 
      } 
     echo "</ul>"; 
     } 
    } 
} 

>

相关问题