【发布时间】:2013-12-03 15:23:13
【问题描述】:
我正在使用 wordpress 主题,我想从另一个页面的 div 内的页面加载内容。
这是我想在 div 中加载的页面代码:
page-usercmets.php(这是一个自定义页面模板,我在其中检索当前用户的 cmets)
<?php
get_header();
?>
<div id="primary" class="row">
<div id="content" class="span9" role="main">
<!-- GET CURRENT USER -->
<?php
global $current_user;
get_currentuserinfo();
echo 'Username: ' . $current_user->user_login . '<br />';
echo 'User display name: ' . $current_user->display_name . '<br />';
?>
<!-- GET COMMENTS OF USER -->
<?php
$args = array(
'user_id' => $current_user->ID, // use user_id
'post_type' => 'debate'
);
$comments = get_comments($args);
?>
<ol class="commentlist">
<?php
wp_list_comments(
array(
'per_page' => 10, //Allow comment pagination
'reverse_top_level' => false //Show the latest comments at the top of the list
),
$comments
);
?>
</ol><!-- .commentlist -->
</div><!-- #content .site-content -->
</div><!-- #primary .content-area -->
<?php get_footer(); // This fxn gets the footer.php file and renders it ?>
我想在另一个页面的 div 中获取此页面的输出,我正在考虑使用 AJAX,代码如下:
更新:
$.ajax({
type: "GET",
url:"http://www.mywebsite.co/cpt/user-comments",
cache: false,
dataType: 'html',
success: function(data){
$("#div").append(data); // <--- look here
},
error: function(){ },
complete: function(){ }
});
});
稍后更新:我已通过使用 WORDPRESS *AJAX API* 解决了这个问题
这是正确的方法吗?
而且,我不知道应该如何添加网址,因为为我要检索的页面创建的永久链接是 "mywebsite.com/user-cmets" 谢谢!
【问题讨论】:
标签: javascript php ajax wordpress jquery