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 關注
- 97 瀏覽
添加回答
舉報