1 回答
TA贡献1886条经验 获得超2个赞
你可以通过 CSS Flex、Order和:nth-child()选择器来做到这一点。
HTML(包含 php):
<div class="row">
<?php if (query_posts('category_name=news'))
if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class('post-contents'); ?> id="post-<?php the_ID(); ?>">
<?php
echo "<div class='image-test'>";
the_post_thumbnail('thumbnail');
echo "</div>";
echo "<div class='tekst-rechts'>";
the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');
the_content();
echo "</div>";
?>
</div>
<?php endwhile; ?>
<?php else : ?>
<p>No posts!</p>
<?php endif; ?>
<?php wp_reset_query(); // reset the query ?>
</div>
CSS:
.post-contents {
display:flex;
flex-flow: row wrap;
justify-content: space-between;
align-items: center;
}
.post-contents:nth-child(odd) .image-test {
order: 2;
}
.post-contens:nth-child(odd) .entry-title {
order: 1;
}
不要忘记在 post_class() 函数中添加 post-contents 类。
- 1 回答
- 0 关注
- 66 浏览
添加回答
举报