2010-11-28 19 views
2

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); ?>&amp;w=300&amp;h=300&amp;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; ? >&amp;color2=febd01&amp;fs=1&amp;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); 
+0

それを解決しました。この関数では?あなたはdisplayLargePost()関数の後でそれを呼び出そうとしましたか?機能全体を教えてください。 –

+0

応答Vladのおかげで!私はcomments_tempateを使用しています。テーマがcomments.phpコードを呼び出すために使用するからです。全体の機能は以下の通りです。クイックアップデート、0はadmin-ajax.phpファイルにあったdie(0)から来ました。私は、include(comments.php)を使用し、comments.phpファイルの中でグローバル$ post $ user_IDと$ user_identityを宣言することで回避策を得ました。 – Ben

+0

Vlad、私はadmin-ajax.phpがwp-load.phpをロードしていることを検証しました。そして、それは一連のコメント関連の機能を持つcomment-template.phpを含むWordpress構造全体をロードします。しかし何らかの理由で、動作していません。 phpが 'comments_template()'にヒットしてもエラーはありません。だから多分それを関数として見ることはできますが、それを実行することはできません。奇妙なことは、The Loopの他のすべてのものが動作することです。 – Ben

答えて

4

comments_templateは投稿のみのために働きますシングルページ。それはあなたが$ withcommentsを使用する必要が動作するように =このような真:

global $withcomments; 

$withcomments = true; 
comments_template(); 

I)は、同様の問題を持っていたし、なぜあなたは(comments_templateを使用しないこのpost

+0

魅力的な作品です。ありがとうございました。 –

関連する問題