使用WP_Query
为了得到你想要的帖子。然后你可以循环浏览它们,得到它们的标题、特色图片和摘录,并按你想要的方式打印出来。诸如此类:
<?php $args = [
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'posts_per_page\' => 9,
\'order\' => \'DESC\',
\'orderby\' => \'date\',
]; ?>
<?php $the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<div class="my-grid">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="grid-item">
<div class="thumbnail"><?php the_post_thumbnail(); ?></div>
<div class="title"><?php the_title(); ?></div>
<div class="excerpt"><?php the_excerpt(); ?></div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div>
<?php else : ?>
<p><?php esc_html_e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php endif; ?>
剩下的只是CSS。