AJAX를 사용하여 테마 함수의 함수에서 comments_template을 호출 할 때 문제가 발생했습니다. 첫 번째 페이지로드가 호출 될 때 제대로 작동하지만 AJAX 중에 호출 될 때는 작동하지 않습니다. 내가 누락 된 일부 포함되어 있다고 생각하지만, 여기에 무엇을 이해하는지 충분히 알지 못합니다.Wordpress comments_template이 AJAX 호출에서 작동하지 않습니다.
내 테마의 function.php 파일에있는 기능 코드의 본질은 다음과 같습니다. (전체 것은 더 이상)
`
다시, 기능은 AJAX 호출이 실행될 때 실행
function displayLargePost ($postid) {
// get the submitted postid parameter if set.
if (!$postid) {
$postid = $_REQUEST['postID'];
}
$myposts = new WP_Query();
$myposts->query('p='.$postid);
while($myposts->have_posts()) : $myposts->the_post();
// some formatting stuff is done then output post content
the_content();
// some more formatting then output the comments template (doesn't work with AJAX)
comments_template();
}
는, 모든 것이 comments_template 출력 '0'을 제외하고 작동합니다.
도움 주셔서 감사합니다.
UPDATE -? (comments.php)를 포함하여 해결 방법을 파악 후 전체 기능은
function displayLargePost ($postid) {
if ($_REQUEST['action'] == "displayLargePost") {
require_once("../wp-load.php");
global $wpdb;
$postid = $_REQUEST['postID'];
$ajax = 1;
}
$myposts = new WP_Query();
$myposts->query('p='.$postid);
while($myposts->have_posts()) : $myposts->the_post();
>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?> data-postid="<?php the_ID(); ?>">
<div class="post-meta-mix clearfix">
<h3 class="post-title post-title-mix"><?php the_title(); ?></h3>
<p class="post-info ">
<span>By <?php the_author_posts_link(); ?></span>
<?php the_time('l F j, Y') ?>
</p>
</div><!-- End div class="post-meta clearfix" -->
<div class="socialdiv socialdiv-mix">
<?php if (function_exists('tweetmeme')) echo tweetmeme(); ?>
<div class="sharebutton">
<fb:share-button href="<?php the_permalink(); ?>" type="button"></fb:share-button>
</div>
<div class="likebutton">
<fb:like href="<?php the_permalink(); ?>" layout="button_count" show_faces="false" width="auto"></fb:like>
</div>
<?php if(get_post_meta($myposts->post->ID, "itunes_link", true)) : ?>
<div class="ituneslink">
<?php echo get_post_meta($myposts->post->ID, "itunes_link", true) ?>
</div>
<?php endif; ?>
<?php if (get_post_meta($myposts->post->ID, "track_number", true) != '-1') : // Don't put the link to add to playlists on the mix intro post
if (function_exists('wpfp_link')) { ?>
<div class="favplaylistlink">
<?php wpfp_link(); ?>
</div>
<?php } endif; ?>
</div><!-- socialdiv -->
<div class="post-box"><!--Single ID post box-->
<div class="page-content clearfix"><!--Single ID post box-->
<div class="clearfix monthlymix-box"><!--Single ID post box-->
<?php if(get_post_meta($myposts->post->ID, "image_value", true)) : ?>
<div class="post-image-inner post-image-mix left">
<img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo get_post_meta($myposts->post->ID, "image_value", true); ?>&w=300&h=300&zc=1" alt="<?php the_title(); ?>" />
</div>
<?php endif; ?>
<?php if(get_post_meta($myposts->post->ID, "download_url", true)) : ?>
<p>
<a href="<?php echo get_post_meta($myposts->post->ID, "download_url", true) ?>" target="blank" type="image/png" >Download this Track</a>
</p>
<?php endif; ?>
<?php
// OUTPUT POST CONTENT
// Remove the YouTube embedded within post, add p tags to keep form
$text = preg_replace('/<center>httpv.*/','',get_the_content());
$text = str_replace("\n", "</p><p>", $text);
echo '<p>'.$text.'</p>';
?>
<br />
</div><!-- End div class="clearfix" --><!--Single ID post box-->
</div><!-- End post-content clearfix --><!--Single ID post box-->
</div><!-- End post-box --><!-- Single ID post box-->
<div class="monthlymix-bottom">
<div class="video-mix">
<div class="post-meta clearfix">
<h3 class="post-title-small left">Video</h3>
<p class="post-info right">
</p>
</div><!-- End post-meta -->
<div class="youtube-mix">
<?php
if (get_post_meta($myposts->post->ID, "youtube_url", true)) :
$video = get_post_meta($myposts->post->ID, "youtube_url", true);
$video = preg_replace('/watch\?v=/', 'v/', $video);
?>
<span class="youtube">
<object width="400" height="325">
<param name="movie" value="<?php echo $video; ?>" />
<param name="allowFullScreen" value="true" />
<embed wmode="transparent" src="<?php echo $video; ? >&color2=febd01&fs=1&showinfo=0" type="application/x-shockwave-flash" allowfullscreen="true" width="400" height="325"></embed>
<param name="wmode" value="transparent" />
</div>
</div>
<div class="commentbox-mix">
<?php
//comments_template();
include('comments.php');
?>
</div>
</div>
</div><!-- End post ID-->
<?php
endwhile; // end of while have posts from new WP Query
wp_reset_query(); // Restore global post data stomped by the_post().
if ($ajax) {
die;
}
}
add_action('wp_ajax_displayLargePost', 'displayLargePost', 10, 1);
add_action('wp_ajax_nopriv_displayLargePost', 'displayLargePost', 10, 1);
에 그것을 해결; 이 함수에서? displayLargePost() 함수 다음에 호출하려고 했습니까? 전체 기능을 제공하십시오. –
응답을 보내 주셔서 감사합니다! 내가 테마를 사용하여 comments.php 코드를 호출하기 때문에 comments_tempate를 사용합니다. 전체 기능은 다음과 같습니다. 빠른 업데이트, 0은 admin-ajax.php 파일에있는 die (0)에서 왔습니다. 나는 include (comments.php)를 사용하고 comments.php 파일 안에 global $ post $ user_ID와 $ user_identity를 선언하여 해결 방법을 얻었습니다. – Ben
블라드 (Vlad)는 admin-ajax.php가 wp-load.php를 로딩한다는 것을 확인했으며, 차례로 커밋 된 코멘트 기능이 포함 된 comment-template.php를 포함하여 전체 Wordpress 구조체를로드해야합니다. 그러나 어떤 이유로, 작동하지 않습니다. php가 'comments_template()'를 눌렀을 때 오류가 없습니다. 그래서 어쩌면 그것은 그것을 함수로보고 있지만 그것을 실행할 수는 없습니까? 이상한 점은 The Loop의 다른 모든 것들이 작동한다는 것입니다. – Ben