我遍历帖子并按category_name = news,如何显示每个帖子的自定义字段?先感谢您。
<?php $preNewsPosts = new WP_Query();
$preNewsPosts->query('posts_per_page=3&category_name=news');
while($preNewsPosts->have_posts()): $preNewsPosts->the_post();
?>
<a href="<?php the_permalink(); ?>" class="atitle" ><?php the_post_thumbnail('thumbnail'); ?><?php the_title(); ?></a>
<?php
the_excerpt();
?>
<hr style="width: 95%; border: 1px solid #e6e6e6; " />
<?php
endwhile;
?>
答案 0 :(得分:1)
这应该可行,只需放在while
循环内。确保将custom_field
更改为自定义字段的名称
echo get_post_meta($preNewsPosts->post->ID, 'custom_field', true);