[英]show custom data in Wordpress posts loop
我需要在類別發布循環中顯示一些自定義數據。 我的意思是我想在我的帖子模板上創建特殊的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();
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.