I need to display some custom data in my category posts loop. I mean I want to create special div on my post template and I want to show data from this div in this posts loop. Can anyone help me? Thank you
<?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 has two powerful functions get_field() and the_field(). To retrieve a field value as a variable, use the get_field() function. This is the most versatile function which will always return a value for any type of field.
To display a field, use the the_field() in a similar fashion.
Now you need to get the name of the field eg if it is '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();
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.