【发布时间】:2026-02-02 03:40:01
【问题描述】:
我想在此代码中的博客页面模板 (template-parts/blog.php) 中添加加载更多帖子按钮。我创建了一个帖子循环,但现在我需要认真的帮助,我尝试了整个互联网但无法通过..我不知道该怎么做才能使加载按钮工作。如何在自定义博客文章循环中添加加载更多按钮?我遵循了许多教程,但它们都不起作用,或者可能是我做错了,但请帮助
<?php
/**
* Template Name: Blog
* The template for displaying blog list.
*
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
get_header();
?>
<div class="main-blog">
<div class="blog-filter">
<div class="container">
<div class="inner-blog">
<div class="blog-heading">
<h2 id="SectionName" >Blog</h2>
</div>
</div>
</div>
</div>
<div class="portfolio section">
<div class="container">
<div class="filters">
<ul class="toolbar">
<li class="active" data-filter="*">All</li>
<?php
$argss = array(
'taxonomy' => 'category',
'hide_empty' => 0,
'include' => array( 17, 18, 19, 20, 21, 22, 23),
);
$termss= get_terms($argss);
$counts = 1;
foreach($termss as $terms){
//print_r($terms);
?>
<li data-filter=".<?php echo $terms->slug; ?>"><div class="cat-img"><img src="<?php echo z_taxonomy_image_url($terms->term_id); ?>" /></div> <?php echo $terms->name; ?></li>
<?php } ?>
</ul>
</div>
<div class="filters-content">
<div id="portfolio" >
<div >
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 15,
'taxonomy' => 'category',
'include' => array( 17, 18, 19, 20, 21, 22, 23),
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$categories = get_the_category();
$cats = "";
foreach($categories as $category){
$cats .= $category->slug." ";
}
?>
<div class="tile scale-anm all <?php echo $cats; //echo get_the_category(); ?>">
<div class="item ">
<div class="img-sec">
<?php the_post_thumbnail(); ?>
</div>
<div class="cnt-sec">
<div class="cat">
<?php
$category_object = get_the_category($loop->ID);
$category_name = $category_object[1]->name;
?>
<p><?php the_category(' '); ?></p>
</div>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p>
<?php the_excerpt(70); ?>
</p>
</div>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
</div></div>
<div id="more_posts">Load More</div>
</div>
</div>
</div>
</div>
</div>
<?php echo do_shortcode( '[elementor-template id="1916"]' ); ?>
<?php get_footer(); ?>
【问题讨论】:
-
这能回答你的问题吗? Load More Posts Ajax Button in WordPress
-
我也试过了,但是当我点击加载更多按钮时它什么也没做。所以我把它恢复到上面的代码。我不明白如何完成它
-
请编辑代码示例以仅包含代码的相关部分,以使您的问题更具可读性。并包含您已经尝试过的方法的更多信息(带有代码示例)。
标签: wordpress wordpress-theming custom-wordpress-pages wordpress-rest-api wordpress-gutenberg