我认为您必须手动输出这些自定义字段才能做到这一点。
您可以这样做(假设您的自定义字段为:first-meta-key
, second-meta-key
, third-meta-key
您可以将其设置为单个值-没有字段分配了多个值):
<ul>
<li><span class="first-post-meta-key">Name: </span> <?php echo esc_html(get_post_meta($post->ID, \'first-meta-key\', true)); ?></li>
<li><span class="second-post-meta-key">Name: </span> <?php echo esc_html(get_post_meta($post->ID, \'second-meta-key\', true)); ?></li>
<li><span class="third-post-meta-key">Name: </span> <?php echo esc_html(get_post_meta($post->ID, \'third-meta-key\', true)); ?></li>
</ul>
另一种方法是:
<?php $custom_fields = get_post_custom($post->ID); ?>
<ul>
<?php foreach ( $custom_fields as $key=>$values ): ?>
<?php foreach ( $my_custom_field as $key => $value ): ?>
<li><span class="<?php echo esc_attr($key); ?><?php echo esc_html($key); ?></span><?php echo esc_html($value); ?></li>;
<?php endforeach; ?>
<?php endforeach; ?>
另外,它没有经过测试(并且直接写在这里),所以可能有点问题。