英文:
How to show only 2 post from post in ACF relationship
问题
从ACF创建自定义字段后,我选择多篇文章。如何仅显示最后的两篇文章?谢谢!
只显示来自关联ACF的2篇文章。
英文:
After creating customfield from ACF. I select multiple articles. How can I show only the last 2 posts? Thank!
Show only 2 post from relationship ACF
答案1
得分: 0
我会使用post_object
字段。有了这个字段,你可以选择要显示的对象,当你将其配置为"多个数值"时。
$featured_posts = get_field('featured_posts');
if( $featured_posts ) { ?>
<ul>
<?php foreach( $featured_posts as $post ) {
setup_postdata($post); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php } ?>
</ul>
<?php
wp_reset_postdata(); ?>
<?php } ?>
英文:
I would use the post_object
field. With this field, you can select which objects you would like to display, when you configure it to "multiple values".
<?php
$featured_posts = get_field('featured_posts');
if( $featured_posts ) { ?>
<ul>
<?php foreach( $featured_posts as $post ) {
setup_postdata($post); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php } ?>
</ul>
<?php
wp_reset_postdata(); ?>
<?php } ?>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论