默认情况下,几乎所有主题都显示类别(及其永久链接)。我正在寻找类似类型的代码添加到我的主题中。从哪里可以买到?要创建自定义分类,我使用More Taxonomies 插件。
如何在帖子中显示自定义分类?
3 个回复
最合适的回答,由SO网友:Bainternet 整理而成
列出自定义分类法的术语并显示它们的最简单方法是使用
<?php get_the_term_list( $id, $taxonomy, $before, $sep, $after ) ?>
例如,在循环中,我的自定义分类法是“作业”列表,如li <ul><?php echo get_the_term_list( $post->ID, \'jobs\', \'<li class="jobs_item">\', \', \', \'</li>\' ) ?></ul>
SO网友:agrublev
此页面上的任何代码都不起作用,但wordpress网站上的示例起作用:
<?php echo get_the_term_list( $post->ID, \'people\', \'People: \', \', \', \'\' ); ?>
我是从http://codex.wordpress.org/Function_Reference/get_the_term_list希望它能帮助其他希望显示当前post分类法的迷失灵魂:)
SO网友:user2260287
看看这个。这对我有用。我有一个名为“stores”的分类法,我想显示其中的2个分类单元。
<?php
$taxonomy = \'stores\';
$args1=array(
\'include\'=> array(12,30)
);
$terms = get_terms(\'stores\',$args1 );
echo \'<ul>\';
foreach ($terms as $term) {
//Always check if it\'s an error before continuing. get_term_link() can be finicky sometimes
$term_link = get_term_link( $term, \'stores\' );
if( is_wp_error( $term_link ) )
continue;
//We successfully got a link. Print it out.
echo \'<li><a href="\' . $term_link . \'">\' . $term->name . \'</a></li>\';
}
echo \'</ul>\';
?>
结束