我需要更改下面的函数,以便在链接而不是字符串时输出列表。所以我需要的html是<a href="#">term</a>
。
function my_post_terms() {
// Get an array of all taxonomies for this post
$taxonomies = get_taxonomies( '', 'names' );
// Are there any taxonomies to get terms from?
if ( $taxonomies ) {
// Call the wp_get_post_terms function to retrieve all terms. It accepts an array of taxonomies as argument.
$arr_terms = wp_get_post_terms( get_the_ID(), array_values( $taxonomies ) , array( "fields" => "names" ) );
// Convert the terms array to a string
$terms = implode( ' ',$arr_terms );
// Get out of here
return $terms;
}
}
答案 0 :(得分:0)
尝试流动代码..
function my_post_terms() {
// Get an array of all taxonomies for this post
$taxonomies = get_taxonomies( '', 'names' );
// Are there any taxonomies to get terms from?
if ( $taxonomies ) {
// Call the wp_get_post_terms function to retrieve all terms. It accepts an array of taxonomies as argument.
$arr_terms = wp_get_post_terms( get_the_ID(), array_values( $taxonomies ) , array( "fields" => "names" ) );
// Convert the terms array to a string
$terms = implode( ' ',$arr_terms );
// Get out of here
if (!filter_var($terms , FILTER_VALIDATE_URL) === false) {
echo "<a href='#'>".$terms."</a>";
}
return $terms;
}
}