weixin_33701251 2015-05-01 08:51 采纳率: 0%
浏览 15

如何获得帖子总数?

Hello I'm making infinite scroll for my custom post type and I dont know how to get max_num_pages and transfer it to javascript. Here is my infinite scroll call:

containerItemSelector = ".home-row";
    counter = 1;
    pageNumber = 1;
    load = true;
    load2 = true;
    loadPosts = function() {
        $.ajax({
            url: templateURL + '/js/load_post.php',
            type: 'GET',
            dataType: 'html',
            data: {
                posts : countPosts,
                page : pageNumber
            },
            beforeSend: function() {
                //$( '#sliders' ).after('<span id="loading"><img src="' + templateURL + '/images/loader.GIF"></span>');
                load = false;
            },
            success: function(data) {
                var item = $(data);
                item.each(function(i) {
                  $(containerItemSelector).append($(this));
                  var slider = $(this).find('.slider-left').attr('id');
                  jssor_slider_left.push(new $JssorSlider$(slider, options1));
                  var total = jssor_slider_left.length - 1;
                  var parentWidth = jssor_slider_left[total].$Elmt.parentNode.clientWidth;

                    if (parentWidth)
                        jssor_slider_left[total].$ScaleWidth(Math.min(parentWidth,954));
                    else
                        window.setTimeout(scales, 30);
                    $(this).find('.img-wrap2').fadeOut(1500, function(){
                        $(this).remove();
                    });
                    if(counter % 2 == 0){
                        $(this).closest('.right-col').after("<div class='clearfix'> </div>");

                }
                counter++;
            });
                $( '#loading' ).remove();
                load = true;
            },
            error: function(result) {
            }
        });
    };

load_post.php:

<?php

define('WP_USE_THEMES', false);
require_once('../../../../wp-load.php');


if (isset($_GET['posts'])) {
    $posts = $_GET['posts'];
}

if ( isset($_GET['page']) ) {
    $page = $_GET['page'];
}
$the_query = new WP_Query( array('post_status'=>'publish', 'post_type' => 'architektura', 'orderby' => 'date', 'order' => 'DESC', 'paged'=>$page) );

 while ( $the_query->have_posts() ) : $the_query->the_post();
     get_template_part('content', 'architektura');
endwhile;

wp_reset_query();
                ?>

How can I get total pages of my posts and then transfer it to javascript to test if there are more posts to load?

  • 写回答

1条回答 默认 最新

报告相同问题?