我在使用Advanced Custom Fields (acf)插件。我使用的“Post对象”使用的代码更少:
<?php
/*
* View array data (for debugging)
*/
var_dump( get_field(\'post_objects\') );
/*
* Loop through post objects (assuming this is a multi-select field) ( setup postdata )
* Using this method, you can use all the normal WP functions as the $post object is temporarily initialized within the loop
* Read more: http://codex.wordpress.org/Template_Tags/get_posts#Reset_after_Postlists_with_offset
*/
$post_objects = get_field(\'post_objects\');
if( $post_objects ): ?>
<ul>
<?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<span>Post Object Custom Field: <?php the_field(\'field_name\'); ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif;
这是来自ACF站点的示例代码。当我尝试在$post\\U objects变量中对帖子分页时,问题开始了,因为它是一个帖子数组,但无法应用<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
漂亮的wp循环,我现在不知道如何为foreach循环分页。有什么建议吗?
弗朗西斯科