我目前正在创建一个短代码,以便将自定义分类法术语显示为我的模板中的列表:
// First we create a function
function list_terms_forme_juridique_taxonomy( $atts ) {
// Inside the function we extract custom taxonomy parameter of our
shortcode
extract( shortcode_atts( array(
'custom_taxonomy' => 'forme_juridique',
),
$atts ) );
// arguments for function wp_list_categories
$args = array(
taxonomy => $custom_taxonomy,
title_li => ''
);
// We wrap it in unordered list
echo '<ul>';
echo wp_list_categories($args);
echo '</ul>';
}
// Add a shortcode that executes our function
add_shortcode( 'forme_juridique', 'list_terms_forme_juridique_taxonomy'
);我讨论了以下两个问题:
任何帮助都很感激!
谢谢
发布于 2018-06-20 10:43:45
首先,您的短代码的输出显示在您的页面顶部,因为您正在回显输出。您应该创建一个$output变量,并使用要显示的内容构建它,然后返回它。例如:
$output = '';
$output .= '<ul>';
$output .= wp_list_categories($args);
$output .= '</ul>';
return $output;第二,由于没有引用数组声明中的键,所以得到了错误。因此,PHP假定它们应该是以前定义的常量。
$args = array(
taxonomy => $custom_taxonomy,
title_li => ''
);应:
$args = array(
'taxonomy' => $custom_taxonomy,
'title_li' => ''
);https://stackoverflow.com/questions/50946170
复制相似问题