【问题标题】:wordpress : how to change the display of meta on single custom post typewordpress:如何在单个自定义帖子类型上更改元的显示
【发布时间】:2015-01-16 18:03:05
【问题描述】:

我找到了用于显示自定义帖子类型的元术语的代码。 但它将元数据显示为垂直列表。 我希望代码连续显示 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> ';
    }

  }

}
?>

【问题讨论】:

    标签: php wordpress post meta


    【解决方案1】:

    这是因为你的 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> ';
    }
    

    【讨论】:

    • 非常感谢您的回复 .. 成功了 .. 但还有一个问题。我需要在术语之间添加一些字符,例如(关键字:消费者、营销、全球。- 进行:2015 年),有什么建议吗?
    • 您可以在回显中的 之后的术语之间添加额外的文本。例如。如果您想在每个术语后添加逗号,则将 echo 语句的结尾更改为 ', ';
    猜你喜欢
    • 1970-01-01
    • 2019-05-08
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多