我想知道你是否可以帮助我显示分类法子链接,例如,我有一个自定义帖子类型的“课程”,其中包含“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
}
}
}
?>
答案 0 :(得分:0)
<?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>';
}
}
}
} ?>