我得到了这个函数,它在没有分页的情况下正常工作,但现在我需要在页面上进行一些分页,因为列表现在已经长大了,我该怎么做呢?
function listing_items($args){
global $wpdb;
$listQ = new WP_Query( $args );
$pid = get_the_ID( );
$return = \'\';
if ( $listQ->have_posts() ) {
while ( $listQ->have_posts() ) {
$listQ->the_post();
$listing = $wpdb->get_results( "SELECT * FROM wp_listings WHERE post_id =".get_the_ID() );
echo $pid;
$summary = $listing[0]->home_description;
$excerpt = wp_trim_words( $summary, $num_words = 25, $more =\'.....\' );
$return .= \'<div class="listing-item" data-location="lat: \'.$listing[0]->lat.\', lng: \'.$listing[0]->lng.\'" data-lat="\'.$listing[0]->lat.\'" data-lng="\'.$listing[0]->lng.\'">\';
$return .= \'<div class="listing-image"><a href="\'.esc_url( get_post_permalink() ).\'">\';
if( $listing[0]->image == \'\' ){
$return .= \'<img src="http://via.placeholder.com/300x300" alt="" />\';
} else {
$return .= \'<img src="\'.home_url().\'/media/listings/\'.get_the_ID().\'/thumb_\'.$listing[0]->image.\'" alt="" />\';
}
$return .= \'</a></div>\';
$return .= \'<div class="listing-details">\';
$return .= \'<h3 class="listing-title"><a href="\'.esc_url( get_post_permalink() ).\'">\'.$listing[0]->title.\'</a></h3>\';
$return .= \'<div class="listing-detail">\'.$listing[0]->accommodates . \' guests<span class="middot">·</span>\' .$listing[0]->bedrooms . \' bedrooms<span class="middot">·</span>\' .$listing[0]->bathrooms . \' bathrooms</div>\';
$return .= \'<div class="listing-excerpt">\' .$excerpt.\'</div>\';
$return .= \'<div class="listing-location"><a class="btn-listing" href="\'.esc_url( get_post_permalink() ).\'">Read More</a></div>\';
$return .= \'</div>\';
$return .= \'</div>\';
}
/* Restore original Post Data*/
wp_reset_postdata();
return $return;
} else {
echo \'<p class="no-response">No Listing yet here</p>\';
}
}