Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在wordpress中显示通过前端添加的评论_Php_Jquery_Ajax_Wordpress - Fatal编程技术网

Php 如何在wordpress中显示通过前端添加的评论

Php 如何在wordpress中显示通过前端添加的评论,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我有一个博客部分,其中包含提交评论的表单。表单代码为: <ul class="comment-list listnone"> <li class="comment"> <div class="comment-body mb40"> <div class="comment-author"><img src="<?php echo content_url().'/themes/medilife

我有一个博客部分,其中包含提交评论的表单。表单代码为:

<ul class="comment-list listnone">
    <li class="comment">
        <div class="comment-body mb40">
            <div class="comment-author"><img src="<?php echo content_url().'/themes/medilife/images/user-pic-2.jpg'?>" alt="" class="img-responsive img-circle"> </div>
            <div class="comment-info">
                <div class="comment-header"><h3 class="user-title">Name</h3></div>
                <div class="comment-content">
                    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
                    <div class="reply"><a href="#" class="btn btn-default btn-sm">Reply</a></div>
                </div>
            </div>
        </div>
    </li>
</ul>
  • “alt=”“class=“img响应img循环”> 名称 知识本身是一种美德,是一种美德,是一种美德,是一种美德,是一种美德,是一种美德,是一种美德,是一种美德,是一种美德,是一种美德,是一种美德

我使用ajax调用将新添加的注释附加到现有注释中,ajax调用是:

jQuery(document).ready(function(){
    jQuery("#reply-form").submit(function(e) {
        e.preventDefault();
        var name = jQuery('#name').val();
        var email = jQuery('#email').val();
        var comment = jQuery('#textarea').val();
        jQuery.ajax({
            type:'POST',
            url:"<?=site_url()?>/ajaxcomment.php",
            data:{name:name, email:email, comment:comment},
            success:function(html){
                jQuery('.comment-list').append(html);
            }
        });
    });
});  
jQuery(文档).ready(函数(){
jQuery(“回复表”).submit(函数(e){
e、 预防默认值();
var name=jQuery('#name').val();
var email=jQuery('#email').val();
var comment=jQuery('#textarea').val();
jQuery.ajax({
类型:'POST',
url:“/ajaxcomment.php”,
数据:{name:name,email:email,comment:comment},
成功:函数(html){
jQuery('.comment list').append(html);
}
});
});
});  
ajax文件是:

<?php
    include 'wp-load.php';
    $id = array(
        'post_title'    =>  $_POST['name'],
        'post_type '        => 'comment'
    );
    // var_dump($userdata);
    $user_id = wp_insert_post( $id ) ;
    // print_r($user_id);
    $comment= $_POST['comment'];
    $email=$_POST['email'];

    add_post_meta($user_id,'comment',$comment);
    add_post_meta($user_id,'email',$email);
?>
<ul class="comment-list listnone">
    <li class="comment">
        <div class="comment-body mb40">
            <div class="comment-author"><img src="<?php echo content_url().'/themes/medilife/images/user-pic-1.jpg'?>" alt="" class="img-responsive img-circle"> </div>
            <div class="comment-info">
                <div class="comment-header"><h3 class="user-title"><?php echo $_POST['name'];?></h3></div>
                <div class="comment-content">
                    <p class="cmnt"><?php echo $_POST['comment'];?></p>
                    <div class="reply"><a href="#" class="btn btn-default btn-sm">Reply</a></div>
                </div>
            </div>
        </div>
    </li>
</ul>

  • “alt=”“class=“img响应img循环”>

因为在ajax调用之后,我没有在html中动态地使用get方法,所以附加的数据丢失了。不管怎样,都可以从后端获取注释,并使其在htm部分成为动态的


我已经创建了一个名为comments的自定义帖子类型,但是由于这些评论是通过前端添加的,因此它们不会在wordpress后端显示为帖子

为什么要将评论存储为帖子?WordPress本来就支持评论…我读到并激活了它。。但是我只能通过后端而不是前端添加评论你说的“前端”和“后端”是什么意思?前端指的是评论表单在我的网站上,后端指的是WordPress的管理面板和控制中心。你为什么试图将评论存储为帖子?WordPress本来就支持评论…我读到并激活了它。。但是我只能通过后端而不是前端添加评论你说的“前端”和“后端”是什么意思?前端指的是评论表单在我的网站上,后端指的是wordpress的管理面板和控制中心