字preSS呈现出从帖子中检索与阿贾克斯 [英] wordpress showing comments from a post retrieved with ajax

查看:152
本文介绍了字preSS呈现出从帖子中检索与阿贾克斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加载与阿贾克斯一职。 在code是

i'm loading a post with ajax. The code is

$(document).ready(function(){

    loadPostsFun = function(){
        $.ajax({
            url: "http://lab1.koalamedia.es/ajax/",
            //url: "/random/",
            success: function(response){
                $("#randomPost").html( response );
            }
        });
    };
    $("#another").click(function(){
        loadPostsFun();
        return false;
    });
});

响应由本code自定义模板生成的:

The response is generated by a custom template with this code:

<?php
    query_posts('showposts=1&orderby=rand');
    the_post();
    $args = array( 'numberposts' => 1, 'orderby' => 'date' );
    $rand_posts = get_posts( $args );
?>
<?php
    foreach( $rand_posts as $post ) :  setup_postdata($post);
?>

    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
      <?php if ( is_front_page() ) { ?>
        <h2 class="entry-title"><?php the_title(); ?></h2>
        <?php } else { ?>
          <h1 class="entry-title"><?php the_title(); ?></h1>
        <?php } ?>

         <div class="entry-content">
          <?php the_content(); ?>
          <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
        <?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?>
        </div><!-- .entry-content -->
      </div><!-- #post-## -->

      <?php 

        //comments_template( '', true ); //this doesn't work
        comment_form(); 
        //wp_list_comments(''); //this doesn't work

      ?>
<?php endforeach; ?>

Ajax请求的作品,但意见并不show.All后的数据是存在的。 我该怎么让评论?

The ajax request works but the comments doesn't show.All the post data is there. How can i show the comments?

既不comments_template或wp_list_comments工作。

neither comments_template or wp_list_comments work.

您可以观看演示或下载模板样本我已经做这里

You can view a demo or download the template sample i've done here

推荐答案

我已经发现了这个问题,我忘了设置全局变量:

i've found the problem, i forgot to set the global variable:

global $withcomments;

我用

$withcomments = true; 
comments_template();

但没有全球没有工作。

but without the global it didn't work.

现在就像正常的意见办。

Now works like normal comments do.

这篇关于字preSS呈现出从帖子中检索与阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆