Php 如何在无限长的卷轴中检测从下到上的偏移量,以及如何让我的卷轴被google crawler抓取?
我有一个自定义的无限卷轴,可以很好地从上到下滚动,我已经成功地添加了一些代码来改变从上到下的滚动,但是用自下而上的方式却失败了。这是我的密码 我声明了一个全局变量my_page=1,从上到下滚动,我将my_page递增1,并确定页面slug和push状态Php 如何在无限长的卷轴中检测从下到上的偏移量,以及如何让我的卷轴被google crawler抓取?,php,ajax,wordpress,woocommerce,infinite-scroll,Php,Ajax,Wordpress,Woocommerce,Infinite Scroll,我有一个自定义的无限卷轴,可以很好地从上到下滚动,我已经成功地添加了一些代码来改变从上到下的滚动,但是用自下而上的方式却失败了。这是我的密码 我声明了一个全局变量my_page=1,从上到下滚动,我将my_page递增1,并确定页面slug和push状态 jQuery(document).ready( function($) { var url = window.location.origin + '/wp-admin/admin-ajax.php', canBeLoaded=tr
jQuery(document).ready( function($) {
var url = window.location.origin + '/wp-admin/admin-ajax.php',
canBeLoaded=true,
bottomOffset = 2000; // the distance (in px) from the page bottom when
you want to load more posts
var my_page=1;
$(window).scroll(function(){
var ga_history = my_ajax_object.ga_history;
var data = {
'action': 'ga_infinite_scroll',
'query': my_ajax_object.posts,
'page' : my_ajax_object.current_page,
//'search_results' : my_ajax_object.ga_search_results,
'search_count' : my_ajax_object.ga_search_count,
'search_posts': my_ajax_object.ga_search_posts,
'search_term' : my_ajax_object.ga_search_term,
'user_currency': my_ajax_object.user_currency,
'reg_price_slug': my_ajax_object.reg_price_field_slug
};
if( $(document).scrollTop() > ( $(document).height() - bottomOffset ) && canBeLoaded == true ){//scroll bottom
$.ajax({//limit the ajax calls
url : url,
data:data,
type:'POST',
beforeSend: function( xhr ){
// you can also add your own preloader here
// you see, the AJAX call is in process, we shouldn't run it again until complete
//console.log(data.search_term);
$('#ajax-loader').show();
canBeLoaded = false;
},
success:function(data){
if( data ) {
//history api handling here
if ( ! window.history.pushState ) {
return;
}
my_page++;
var pageSlug = window.location.protocol + '//' + ga_history.host + ga_history.path.replace( /%d/, my_page ) + ga_history.parameters;
if ( window.location.href != pageSlug ) {
history.pushState( null, null, pageSlug );
}
// Fire Google Analytics pageview
//if ( self.google_analytics ) {
var ga_url = history.path.replace( /%d/, self.page );
if ( 'object' === typeof _gaq ) {
_gaq.push( [ '_trackPageview', ga_url ] );
}
if ( 'function' === typeof ga ) {
ga( 'send', 'pageview', ga_url );
}
//}
$('#multiple-products .columns-3 .products ').find('li:last-of-type').after( data ); // where to insert posts
canBeLoaded = true; // the ajax is completed, now we can run it again
my_ajax_object.current_page++;
$('#ajax-loader').hide();
}
else{
//$('#ajax-loader').html('End of products...').delay(1000).fadeOut();
$('#ajax-loader').fadeOut();
return;
}
}
});
}
else {//bottom to top, this fails
if( my_page!=1) {
my_page--;
var pageSlug = window.location.protocol + '//' + ga_history.host + ga_history.path.replace( /%d/, my_page ) + ga_history.parameters;
if ( window.location.href != pageSlug ) {
history.pushState( null, null, pageSlug );
}
}
else{
return;
}
});
});
我的HTML结构是一个标准的店面主题结构(卷轴在商店中实现)。
在这个场景中,我无法识别从下到上的滚动(代码被注释//从下到上)。另外,我想知道代码(注释//Fire Google Analytics pageview)是否对Google crawler有用