我想在网页的左侧显示我的所有帖子分类法,这样当人们单击它时,帖子可以根据分类法显示。是否有任何方式来显示它们,我也想在其中添加一些样式。
分类归档索引页链接列表
1 个回复
最合适的回答,由SO网友:Chip Bennett 整理而成
可以使用两个函数构建列表:get_terms()
和get_term_link()
:
<?php
function wpse73271_get_term_archive_link_list( $taxonomy ) {
// First, get an array of term IDs
$term_objects = get_terms( $taxonomy );
// Now, loop through $term_ids and get
// an array of term archive permalinks
foreach ( $term_objects as $term_object ) {
$term_object->url = get_term_link( $term_object, $taxonomy );
$term_object->permalink = \'<a href="\' . $term_object->url . \'">\' . $term_object->name . \'</a>\';
}
// Now, build an HTML list of permalinks:
$output = \'<ul>\';
foreach ( $term_objects as $term_object ) {
$output .= \'<li>\' . $term_object->permalink . \'</li>\';
}
$output .= \'</ul>\';
// Now return the output
return $output;
}
?>
结束