如何在 ACF 关联中仅显示 2 篇文章。

huangapple go评论48阅读模式
英文:

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".

&lt;?php
$featured_posts = get_field(&#39;featured_posts&#39;);
if( $featured_posts ) { ?&gt;
 &lt;ul&gt;
 &lt;?php foreach( $featured_posts as $post ) {
    setup_postdata($post); ?&gt;
    &lt;li&gt;
        &lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;
    &lt;/li&gt;
&lt;?php } ?&gt;
&lt;/ul&gt;
&lt;?php 
wp_reset_postdata(); ?&gt;
&lt;?php } ?&gt;

huangapple
  • 本文由 发表于 2023年2月8日 15:13:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75382433.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定