我在几年前的另一个StackExchange问题中也提到了这一点,当时的布局大致如下:
<div class=items active>
<div class=row>
<div class=1b>
--content of first post in loop--
</div>
<div class=1c>
--content of second post in loop--
</div>
<div class=1d>
--content of third post in loop--
</div>
<div class=1e>
--content of fourth post in loop--
</div>
</div>
</div>
<div class=items> -- Note the lack of the active class for this div and row --
<div class=row>
<div class=2b>
--content of fifth post in loop--
</div>
<div class=2c>
--content of sixth post in loop--
</div>
<div class=2d>
--content of seventh post in loop--
</div>
<div class=2e>
--content of eighth post in loop--
</div>
</div>
</div>
但是,解决方案似乎没有使用任何自定义帖子类型。
下面是我的代码,试图修改另一个线程中提供的代码,但我的循环中根本没有显示任何内容(请注意,我认为原始线程的更改是每3篇帖子发生一次,而不是像我在这里看到的每4篇帖子,因此我很可能在下面的数字有误:(
add_shortcode( \'partnerlogos\', \'display_custom_post_type\' );
function display_custom_post_type(){
$args = array(
\'post_type\' => \'dnf_partner_logos\',
\'post_status\' => \'publish\'
);
$query = new WP_Query( $args );
while( have_posts() ) : the_post();
$image = get_field(\'partner_logo\');
$position = $wp_query->current_post;
$p3 = $position%4;
$p6 = $position%8;
$number_posts = $wp_query->post_count-1;
// vars
$url = $image[\'url\'];
$title = $image[\'title\'];
$alt = $image[\'alt\'];
$caption = $image[\'caption\'];
// thumbnail
$size = \'dnf-partners\';
$thumb = $image[\'sizes\'][ $size ];
$width = $image[\'sizes\'][ $size . \'-width\' ];
$height = $image[\'sizes\'][ $size . \'-height\' ];
if( $p3 == 0 ) echo \'<div class="item active"><div class="row">\';
if( $p6 == 0 ) echo \'<div class="col-md-3">\';
elseif( $p6 == 1 || $p6 == 3) echo \'<div class="item"><div class="row"\';
elseif( $p6 == 5 ) echo \'<div class="col-md-3">\'; ?>
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>"/><!--item-->
<?php if( $position == $number_posts || in_array($p6, array(0, 2, 4, 5)) ) echo \'</div>\';
if( $p3 == 2 || $position == $number_posts ) echo \'</div></div><!--layer-->\';
endwhile;
}