我试图在我的网站上应用本教程
Getting Loopy - Ajax Powered Loops with jQuery and WordPress
我已应用所有内容,但我从Chrome控制台收到此错误
Uncaught TypeError: undefined is not a function
这是我的代码:
// ajaxLoop.js
jQuery(function($){
var page = 1;
var loading = true;
var $window = $(window);
var $content = $("#articles-wrapper");
var load_posts = function(){
$.ajax({
type : "GET",
data : {numPosts : 5, pageNumber: page},
dataType : "html",
url : "http://www.dzlng.com/demo/wp-content/themes/dzlng/loopHandler.php",
beforeSend : function(){
if(page != 1){
/* $content.append('<div id="temp_load" style="text-align:center">\
loading....\
</div>');*/
}
},
success : function(html){
$data = $(html);
if($data.length){
//$data.hide();
var newItems = $(html).appendTo($("#articles-wrapper"));
imagesLoaded('#articles-wrapper', function() {
$("#articles-wrapper").isotope('appended', newItems );
});
$data.fadeIn(500, function(){
$("#temp_load").remove();
loading = false;
});
} else {
$("#temp_load").remove();
}
},
error : function(jqXHR, textStatus, errorThrown) {
$("#temp_load").remove();
alert(jqXHR + " :: " + textStatus + " :: " + errorThrown);
}
});
}
$window.scroll(function() {
var content_offset = $content.offset();
//console.log(content_offset.top);
if(!loading && ($window.scrollTop() +
$window.height()) > ($content.scrollTop() + $content.height() + content_offset.top)) {
loading = true;
page++;
load_posts();
}
});
load_posts();
});
和
<?php
//loopHandler.php
// Our include
define('WP_USE_THEMES', false);
require_once('../../../wp-load.php');
// Our variables
$numPosts = (isset($_GET['numPosts'])) ? $_GET['numPosts'] : 0;
$page = (isset($_GET['pageNumber'])) ? $_GET['pageNumber'] : 0;
query_posts(array(
'posts_per_page' => $numPosts,
'paged' => $page
));
// our loop
if (have_posts()) {
while (have_posts()){
the_post();
get_template_part( 'content', 'item' );
}
}
wp_reset_query();
?>
我尝试了一些东西,但它没有用。