在我的网站中,我使用 get posts 获取自定义帖子类型的帖子。但是一次获取所有帖子,但在我的模板中,我想显示每页剩余的 x 个帖子,我想通过使用加载更多按钮加载。
<?php
$id = url_to_postid( $current_url );
$queried_post = get_post($id);
$post_slug = $queried_post->post_name;
$page_number = (get_query_var('paged')) ?
get_query_var('paged') : 1;
$page_link = get_pagenum_link(9999999999);
$term = get_term_by('slug', $post_slug,
'tax_business_listing');
$cat_term_id = $term->term_id;
$args = array(
'posts_per_page' =>3,
'paged'=>$page_number,
'order' => 'ASC',
'post_type' => 'business',
'post_status' => 'publish',
'offset' => 0,
'orderby' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'tax_business_listing',
'field' => 'term_id',
'terms' => $cat_term_id,
)
),
);
$posts = get_posts( $args );
$loop = new WP_Query( $args );
$count = !empty($loop->posts)?count($loop->posts):0;
$max_page = $loop->max_num_pages;
$i=0;
if(!empty($posts)){
foreach ($posts as $post):
$i++;
$postName = $post->post_title;
$exp = $post->post_excerpt;
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id,
'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];
通过包含上面的代码,我在点击加载更多按钮后获得第一个帖子 3 次。我想加载剩余的帖子。请帮助我获得预期的结果。非常感谢任何帮助..
皈依舞