我需要在类别发布循环中显示一些自定义数据。我的意思是我想在我的帖子模板上创建特殊的div,并希望在此帖子循环中显示该div的数据。谁能帮我?谢谢
<?php
if ( have_posts() ) :
query_posts('cat=7');
while (have_posts()) : the_post(); ?>
<div class = "item">
<div class="item_image"><?php the_post_thumbnail(); ?></div>
<div class = "item_title"><?php the_title(); ?></div>
<div class = "item_excerpt"><?php the_excerpt(10); ?></div>
<!-- here I want to display data from each post -->
<div class = "my_custom_data">custom data</div>
<a href = "<?php the_permalink(); ?>" class = "item_link">Show more...</a>
</div>
<?php endwhile;
endif;
wp_reset_query();
?>
ACF具有两个强大的函数get_field()和the_field()。要将字段值检索为变量,请使用get_field()函数。这是最通用的函数,它将始终为任何类型的字段返回一个值。
要显示字段,请以类似方式使用the_field()。
现在,您需要获取字段名称,例如,如果它是“ custom_title”
<?php
if ( have_posts() ) :
query_posts('cat=7');
while (have_posts()) : the_post(); ?>
<div class = "item">
<div class="item_image"><?php the_post_thumbnail(); ?></div>
<div class = "item_title"><?php the_title(); ?></div>
<div class = "item_excerpt"><?php the_excerpt(10); ?></div>
<!-- here I want to display data from each post -->
<div class = "my_custom_data"><?php the_field('custom_title'); ?></div>
<a href = "<?php the_permalink(); ?>" class = "item_link">Show more...</a>
</div>
<?php endwhile;
endif;
wp_reset_query();
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句