0

我想知道您是否可以帮助我显示分类子链接,例如,我有一个自定义帖子类型为“课程”,自定义分类为“study_type”以及“安全”、“专业”等类别。目前我是正确显示类别标题和描述。我需要知道如何获取属于类别的课程的永久链接并将它们显示在类别描述下方。感谢您提供的任何帮助或建议。这是我的代码:

<?php
//list terms in taxonomy
$types[0] = 'study_type';

 foreach ($types as $type) {
 $taxonomy = $type;
 $terms = get_terms( $taxonomy, '' );
 if ($terms) {
  foreach($terms as $term) {
    echo '<h2>'.$term->name.'</h2>';
    echo '<p>' . $term->description . '</p>';
    //This is where the links should be
 }
 }
 }
?>
4

1 回答 1

0

使用get_term_children

<?php
//list terms in taxonomy
$types[0] = 'study_type';

foreach ($types as $type) {
 $terms = get_terms( $type, '' );
 if ($terms) {
  foreach($terms as $term) {
   echo '<h2>'.$term->name.'</h2>';
   echo '<p>' . $term->description . '</p>';
   //This is where the links should be
   $termchildren = get_term_children( $term->term_id,  $type );
   if($termchildren){
    echo '<ul>';
    foreach ( $termchildren as $child ) {
     $term = get_term_by( 'id', $child, $taxonomy_name );
     echo '<li><a href="' . get_term_link( $term->name, $type ) . '">' . $term->name . '</a></li>';
    }
    echo '</ul>';
   }
  }
 }
} ?> 
于 2013-06-05T22:03:36.597 回答