Wordpress:创建左/右帖子布局
问题描述:
I'm building a WP theme and was looking to arrange my archive so that the layout flipped with each post. Essentially, have the featured image thumbnail appear on the left of one post, and then on the right of the next.
Very similar to this: http://equinox-template.blogspot.co.uk/
Has anyone got any ideas on how to do this?
Thanks in advance!
我正在构建一个WP主题,并且正在寻找我的档案,以便每个帖子翻转布局。 基本上,将特色图像缩略图显示在一个帖子的左侧,然后显示在下一个帖子的右侧。 p>
与此非常相似: http:// equinox-template .blogspot.co.uk / p>
有没有人对如何做到这一点有任何想法? p>
提前致谢! p> div>
答
WordPress has a count of the post inside the loop, use it in the even odd fashion. If you are using WP_Query
instance then it will be $var->current_post
.
<?php
while (have_posts()): the_post()
if ($wp_query->current_post % 2 == 0):
?>
Markup for even content
<?php else: ?>
Markup for odd content
<?php
endif;
endwhile;
?>