我有一个连接到“template\\u redirect”(ajax请求帖子的url)的ajax请求,我只想显示评论模板:
function get_comm(){
if(isset($_GET[\'get_my_comments\'])):
$offset = intval($_GET[\'get_my_comments\']);
echo $offset; // offset will be the same as "cpage"
global $comments, $wp_query, $post, $id;
print_r($comments); // nothing ?
print_r($wp_query->comments); // nothing ??
wp_list_comments(\'type=comment\', $comments); // same :(
exit();
endif;
}
add_action(\'template_redirect\', \'get_comm\');
javascript部分工作正常,如下所示: $("a.show-more-comments").live("click", function(){
var offset = $(this).attr(\'rel\');
var list = $(this).closest("#comments");
$.ajax({
url: "<?php echo get_permalink($post->ID); ?>",
type: "GET",
data: ({
get_my_comments: offset
}),
success: function(data){
list.append(data);
}
});
});
问题是$comments
或$wp_query->comments
似乎未初始化。我做错了什么?