div包装器位于while循环中,并由if子句拆分。这无法正常工作,因为您的循环将生成多达14个id为ajax的div。
将开始div标记放在if ( $the_query->have_posts() ) {
以及之后的关闭wp_reset_postdata();
你应该没事的。
Edit
您确定没有遗漏任何打开/关闭php标记吗?e、 g.load\\u more\\u button()是用php包装的,但您之前没有关闭php。
<?php
/*
* Template Name:
*/
get_header();
get_template_part (\'inc/carousel\');
$the_query = new WP_Query( [
\'posts_per_page\' => 14,
\'paged\' => get_query_var(\'paged\', 1)
] );
if ( $the_query->have_posts() ) { ?>
<div id="ajax">
<?php
$i = 0;
while ( $the_query->have_posts() ) { $the_query->the_post();
if ( $i % 7 === 0 ) { // Large post: on the first iteration and every 7th post after... ?>
<article <?php post_class( \'col-md-12\' ); ?>>
<?php the_post_thumbnail(\'large-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\'); ?>
</article><?php
} else { // Small posts ?>
<article <?php post_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\'); ?>
</article>
<?php
}
$i++;
}?>
</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();