【发布时间】:2013-12-22 00:01:32
【问题描述】:
我正在构建一个 wordpress 页面(基于 quark,使用 ACF),使用 foreach(get_field('exhibitions') as $post_object) 显示来自其他帖子的信息
我希望包含来自其他帖子的信息的“col grid_3_of_12-divs”在 div 中分组,每个 div 中有四个。与此问题的作者类似的问题:Is there an easy way to do 4 at a time in a php foreach loop
我已经尝试过使用 array_chunk,但似乎无法在不弄乱从其他帖子中检索信息的情况下做到这一点。
有人可以帮我解决这个问题吗?
我是一个自学的php初学者,如果我的代码很愚蠢,请见谅..
<?php get_header(); ?>
<div id="primary" class="site-content row clearfix" role="main">
<div class="col grid_12_of_12">
<?php while ( have_posts() ) : the_post(); ?>
<?php foreach(get_field('exhibitions') as $post_object): ?>
<a href="<?php echo get_permalink($post_object->ID); ?>">
<div class="col grid_3_of_12">
<h3 class="exhibition title"> <?php echo $post_object->short_title?> </h3>
<?php $attachment_id = $post_object->thumbnail;
$image_attributes = wp_get_attachment_image_src( $attachment_id, 'full' ); ?>
<img src="<?php echo $image_attributes[0]; ?>">
<p class="exhibition short desc"> <?php echo $post_object->short_description?> </p>
</div>
</a>
<?php endforeach; ?>
<?php content_nav( 'nav-below' ); ?>
<?php endwhile; ?>
</div>
</div>
【问题讨论】: