繁体   English   中英

如何在网格布局中显示帖子

[英]how to display posts in a grid layout

我试图创建一个页面,显示我的帖子的所有档案帖子与类别食物(类别ID是10)。 我正在尝试使用col-md-4进行设置,所以我会在一行中有三个帖子。 我想我在php文件中添加了所有必要的元素,我现在还不知道如何设置它。 我试图设置它以便有3个帖子的3个帖子(所以12个帖子)然后在每12个帖子后它会加载ajax加载更多按钮。 任何人都可以帮我解决这个问题。 提前致谢。

更新它仍然没有正确循环通过帖子 - 它只显示1个帖子

 <?php get_header(); get_template_part ('inc/carousel-food'); $the_query = new WP_Query( [ 'posts_per_page' => 12, 'paged' => get_query_var('paged', 1) ] ); if ( $the_query->have_posts() ) { ?> <div id="ajax"> <article class="post"> <div class="row"> <div class="col-md-4"><?php the_post_thumbnail('medium-thumbnail'); ?> <h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p class="post-excerpt"><?php echo get_the_excerpt(); ?></p> <?php get_template_part( 'share-buttons' ); ?> <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> <?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'comment-count', 'none'); ?> </div> </div> </article> </div> <?php if(get_query_var('paged') < $the_query->max_num_pages) { load_more_button(); } } elseif (!get_query_var('paged') || get_query_var('paged') == '1') { echo '<p>Sorry, no posts matched your criteria.</p>'; } wp_reset_postdata(); get_footer(); 

你错过了一个循环,它将重复你的帖子代码,每个帖子一次。

<article>周围添加:

<?php while ( $the_query->have_posts() ) : ?>

   <?php $the_query->the_post(); ?>

   <article> ...

   ... </article>

<?php endwhile; ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM