【发布时间】:2016-06-30 14:18:27
【问题描述】:
我买了一个wordpress模板,尝试修改品牌页面的代码显示3栏。以下是场景:
当前显示:
a | b | c | d
e | f | g | h
i | j | k
我想让显示器变成
a | d | g
b | e | h
c | f | i
下面的代码显示当前代码。谁能帮我更正下面的代码以显示上述情况。
代码:
<?php
$args = array(
'post_type' => 'partner',
'posts_per_page' => '-1',
'order' => 'ASC',
'post__not_in' => array( $post->ID )
);
// the query
$query = new WP_Query( $args );
// The Loop
?>
<section class="recent-posts clear">
<?php
$lastChar = '';
$count_posts = wp_count_posts('partner')->publish;
$i = 0;
?>
<?php if ($query->have_posts()) : while($query->have_posts()) : $i++;
if(($i % 3) == 0) : else : $query->the_post(); ?>
<?php
global $post;
$brandname = $post->post_title;
$char = $brandname[0];
?>
<div style="float:left; width:24%; margin-right:10px;">
<?php
if ($char !== $lastChar) {
if ($lastChar !== '')
echo '<br>';
echo "<div style='padding:10px; background:red;
color:white; font-weight:bold;'>" .strtoupper($char)."</div>";
//print A / B / C etc
$lastChar = $char;
}
echo $brandname;
?>
<?php the_content(); ?>
</div>
<?php endif; endwhile; else: ?>
<div>Alternate content</div>
<?php endif; ?>
</section>
【问题讨论】:
标签: wordpress post types multiple-columns