-
AuthorPosts
-
November 18, 2017 at 12:14 am #878332ediaGuest
hi i use below code but doesn’t work!
function goToPage(pageNumber){jQuery.ajax({url:my_theme.ajax_url,type:”post”,data:{action:”lazy_comments”,post_id:my_theme.post_id,cpage:pageNumber,total:window.commentsLazyLoad.totalPage},beforeSend:function(){jQuery(“#comments .pagination a”).addClass(“disabled”);jQuery(“#commentlist-container”).find(“.comment-spinner”).remove();jQuery(“#commentlist-container”).append(‘<div class=”comment-spinner pull-left”></div>’);},error:function(jqXHR,textStatus,errorThrown){jQuery(“#comments .pagination a”).removeClass(“disabled”);jQuery(“#commentlist-container”).find(“.comment-spinner”).remove();},success:function(response){var r=jQuery.parseJSON(response);jQuery(“#comments .pagination”).closest(“div”).remove();jQuery(r.comment_pagination).insertAfter(“#commentlist-container”);jQuery(“.comment_list”).html(r.commentlist);jQuery(“#commentlist-container”).find(“.comment-spinner”).remove();jQuery(“body,html”).animate({scrollTop:jQuery(“#comments”).offset().top-50},400);}});return 1;}function historyPush(pageNumber,path){var hash=location.hash?”/”+location.hash:”/#comments”;var uri=path+hash;var stateObj={cpage:pageNumber,total:window.commentsLazyLoad.totalPage,post_id:my_theme.post_id,path:path};history.pushState(stateObj,document.title,uri);}jQuery(“#comments”).on(“click”,”.pagination a”,function(e){e.preventDefault();var $this=jQuery(this);var page=parseInt($this.text().replace(/[^0-9.]/g,””),10);window.commentsLazyLoad.cpage=page>0?page:1;var href=$this.attr(“href”).lastIndexOf(“comment-page-“)>0?$this.attr(“href”):$this.attr(“href”)+”comment-page-“+window.commentsLazyLoad.cpage;historyPush(window.commentsLazyLoad.cpage,href);goToPage(window.commentsLazyLoad.cpage,href);jQuery(this).blur();});window.onpopstate=function(event){goToPage(event.state.cpage,event.state.path);};
code in function.php
add_action(‘wp_ajax_lazy_comments’, ‘lazy_comments’);
add_action(‘wp_ajax_nopriv_lazy_comments’, ‘lazy_comments’);
function lazy_comments()
{
$cpage = (int)$_POST[‘cpage’];
$total_page = (int)$_POST[‘total’];
$args = array(
‘current’ => $cpage,
‘total’ => $total_page,);
$my_pagination = paginate_comments_links($args);
$my_commentlist = wp_list_comments();
$response[‘comment_pagination’] = ‘<div class=”pagination”>’.$my_pagination.'</div>’;
$response[‘commentlist’] = $my_commentlist;
echo json_encode($response,true);
die();
}
the paginate_comments_links() docent work in function.php why?! thanksNovember 19, 2017 at 9:01 am #878724 -
AuthorPosts
- You must be logged in to reply to this topic.