我正在尝试将插件“Easy Load More”添加到我的主题中(https://wordpress.org/plugins/easy-load-more/). 你应该把它包起来<div id="ajax">
然后放置<?php load_more_button(); ?>
您希望加载更多按钮的位置。我不太清楚添加此代码的正确位置(正如您可以从下面的代码中看到的,它当前位于错误的位置)。下面是我希望“加载更多”按钮的外观图片。
front-page.php
<?php
/*
* Template Name:
*/
get_header();
get_template_part (\'inc/carousel\');
$the_query = new WP_Query( [
\'posts_per_page\' => 14,
\'paged\' => $paged
] );
if ( $the_query->have_posts() ) {
load_more_button();
?>
<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++;
}
wp_reset_postdata();?>
</div>
<?php
}
else {
echo \'<p>Sorry, no posts matched your criteria.</p>\';
}
load_more_button();
get_footer();