我的网站上的分页不起作用。我可以看到以前的开发人员将WP-navi与Advanced自定义字段集成在一起。请参见下面的代码。显示分页,但是当您单击2或任何数字时。网址刚刚添加了/ page / 3 /,但您仍在第1页上。
任何解决此问题的建议。
预先感谢
function get_all_trucks( $atts){
add_filter( 'posts_orderby' , 'posts_orderby_lastname' );
$var = shortcode_atts( array(
'number_of_post' => 3,
'show_navigation' => 'true',
'show_post_thumbnail' => $show_post_thumbnail,
'post_order' => $post_order,
'vehicle_make' => $vehicle_make,
'vehicle_type' => $vehicle_type
), $atts );
if ( empty($var['number_of_post'])) {
$var['number_of_post'] = 10;
}
if ( empty($var['show_navigation'])) {
$var['show_navigation'] = 'true';
}
if ( empty($var['show_post_thumbnail'])) {
$var['show_post_thumbnail'] = 'true';
}
$output = NULL;
if ( empty($var['vehicle_type'])) {
$args = array( 'post_type' => 'vehicle',
'post_status' => 'publish',
'posts_per_page' => $var['number_of_post'],
'orderby' => 'name',
'order' => 'ASC',
'taxonomy' => 'make',
'term' => $var['vehicle_make'] );
} else {
$args = array( 'post_type' => 'vehicle',
'post_status' => 'publish',
'posts_per_page' => $var['number_of_post'],
'orderby' => 'name',
'order' => 'ASC',
'taxonomy' => 'make',
'term' => $var['vehicle_make'],
'meta_query' => array(
array( 'key' => 'vehicle_type',
'value' => "{$var['vehicle_type']}",
'compare' => '=='
)
)
);
}
$vehicle = new WP_Query( $args );
while ( $vehicle->have_posts() ) : $vehicle->the_post();
$terms = wp_get_post_terms( $vehicle->post->ID, 'make'); //var_dump($terms)
$model = wp_get_post_terms( $vehicle->post->ID, 'vehicle_model'); //var_dump($terms)
$output .= '<div class="trucks-container-box"><div class="et_pb_row" style="width:100%;">';
$output .='<div class="et_pb_column et_pb_column_1_3">';
if ($var['show_post_thumbnail'] == 'true') {
$output .= '<div class="truck-img-container">' . get_the_post_thumbnail( $vehicle->post->ID, 'thumbnail') . '</div>';
}
$output .='</div>';
$output .='<div class="et_pb_column et_pb_column_2_3">';
$output .= '<h3>'.get_the_title().'</h3>';
$output .= '<div class="truck-content">'.get_the_excerpt();
$output .= '<table width="100%" class="table-details">';
$output .= '<tr>';
$output .= '<th class="details-label"><strong>Make:</strong></th>';
$output .= '<td>'.$terms[0]->name.'</td>';
$output .= '<th class="details-label"><strong>Price</strong></th>';
$truck_price = get_field('truck_price', $vehicle->post->ID, true);
if ( !empty($truck_price)) {
$output .= '<td> $'.get_field('truck_price', $vehicle->post->ID, true).'+GST</td>';
} else {
$output .='<td></td>';
}
$output .= '</tr>';
$output .= '<tr>';
$output .= '<th class="details-label"><strong>Model:</strong></th>';
$output .= '<td>'.$model[0]->name.'</td>';
$output .= '<th class="details-label"><strong>Type</strong></th>';
$output .= '<td>'.ucwords(str_replace('-', ' ', get_field('vehicle_type', $vehicle->post->ID, true))).'</td>';
$output .= '</tr>';
$output .= '</table>';
$output .= '</div>';
$output .= '<p class="btn-container"><a href="'.get_the_permalink().'">View Details <i class="arrow-right"></i></a></p>';
$output .='</div>';
$output .= '</div></div>';
endwhile;
remove_filter( 'posts_orderby' , 'posts_orderby_lastname' );
if ($var['show_navigation'] == 'true') {
$output .= '<div class="custom-pagination">' . wp_pagenavi( array( 'query' => $vehicle, 'echo'=>false ) ) . '</div>';
}
return $output;
}