wordpress:如何在单个自定义 post 类型上更改元数据的显示
wordpress : how to change the display of meta on single custom post type
我找到了显示自定义 post 类型的元术语的代码。
但它将元数据显示为垂直列表。
相反,我希望代码连续显示 CPT 元数据。
有什么帮助吗?
代码:
<?php
//get all taxonomies and terms for this post (uses post's post_type)
foreach ( (array) get_object_taxonomies($post->post_type) as $taxonomy ) {
$object_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'all'));
if ($object_terms) {
echo '- '.$taxonomy;
foreach ($object_terms as $term) {
echo '<p><a href="' . esc_attr(get_term_link($term, $taxonomy)) .
'" title="' . sprintf( __( "View all posts in %s" ), $term->name ) .
'" ' . '>' . $term->name.'</a><p> ';
}
}
}
?>
这是因为您的 foreach 循环中的 HTML 标记,请尝试将段落标记删除为:
foreach ($object_terms as $term) {
echo '<a href="' . esc_attr(get_term_link($term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> ';
}
我找到了显示自定义 post 类型的元术语的代码。 但它将元数据显示为垂直列表。 相反,我希望代码连续显示 CPT 元数据。 有什么帮助吗? 代码:
<?php
//get all taxonomies and terms for this post (uses post's post_type)
foreach ( (array) get_object_taxonomies($post->post_type) as $taxonomy ) {
$object_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'all'));
if ($object_terms) {
echo '- '.$taxonomy;
foreach ($object_terms as $term) {
echo '<p><a href="' . esc_attr(get_term_link($term, $taxonomy)) .
'" title="' . sprintf( __( "View all posts in %s" ), $term->name ) .
'" ' . '>' . $term->name.'</a><p> ';
}
}
}
?>
这是因为您的 foreach 循环中的 HTML 标记,请尝试将段落标记删除为:
foreach ($object_terms as $term) {
echo '<a href="' . esc_attr(get_term_link($term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> ';
}