我需要一些帮助如何在所选页面上显示自定义分类?我的意思是我有3个自定义分类法位置、持续时间和;coursesi已经创建了三个页面,我想在其中显示这些自定义分类法的术语,我已经使用函数在我的帖子中显示了这些术语
<?php echo do_shortcode("[terms]"); ?>
但同样的事情我也想在我的页面上显示,我怎么能做到呢??????我需要一些帮助如何在所选页面上显示自定义分类?我的意思是我有3个自定义分类法位置、持续时间和;coursesi已经创建了三个页面,我想在其中显示这些自定义分类法的术语,我已经使用函数在我的帖子中显示了这些术语
<?php echo do_shortcode("[terms]"); ?>
但同样的事情我也想在我的页面上显示,我怎么能做到呢??????如果要显示分类法中所有术语的列表,可以调用wp_list_categories()
并通过taxonomy
参数获取除类别以外的任何内容:
wp_list_categories( array(
\'taxonomy\' => \'your-taxonomy\'
) );
如果您想为此使用快捷码,以便可以在帖子内容中使用它,请使用add_shortcode()
. 此未经测试的示例代码允许您使用[taxonomy_terms]
或[taxonomy_terms taxonomy=my-taxonomy]
在您的内容中:add_shortcode( \'taxonomy_terms\', \'wpse4668_taxonomies\' );
function wpse4668_taxonomies( $atts )
{
// Sanitize our input
$atts = shortcode_atts( array(
\'taxonomy\' => \'your-default-taxonomy\',
), $atts );
// Don\'t echo the output, just return it
$atts[\'echo\'] = 0;
return wp_list_categories( $atts );
}