也想出现在这里?联系我们

调用wordpress编辑器wp_editor作用文章评论框

2023.11.09 wordpress教程
  • 文章介绍
  • 升级版本
  • 评价&建议

要在WordPress中使用wp_editor函数创建文章评论框,你可以在主题文件中的评论表单中添加以下代码。通常,这将包括在comments.phpsingle.php文件中,具体取决于你的主题结构。

下面是一个示例代码,它将wp_editor用于评论表单:

<?php
// 检查是否允许评论
if (comments_open()) :
?>

<div id="respond">
    <h3><?php comment_form_title('Leave a Comment', 'Leave a Reply to %s'); ?></h3>
    <div id="cancelcommentreply">
        <small><?php cancel_comment_reply_link(); ?></small>
    </div>

    <?php if (get_option('comment_registration') && !is_user_logged_in()) : ?>
        <p>You must be <a href="<?php echo wp_login_url(get_permalink()); ?>">logged in</a> to post a comment.</p>
    <?php else : ?>

        <form action="<?php echo site_url('/wpcommentspost.php'); ?>" method="post" id="commentform">
            <?php
            // 获取当前用户信息
            $user = wp_get_current_user();

            // 构建评论字段参数
            $comment_args = array(
                'comment_field' => '<div class="commentformcomment"><label for="comment">Comment</label>' .
                    '<textarea id="comment" name="comment" cols="45" rows="8" ariarequired="true"></textarea></div>',
                'fields' => apply_filters('comment_form_default_fields', array(
                    'author' => '<div class="commentformauthor">' .
                        '<label for="author">Name ' . ($req ? '<span class="required"></span>' : '') . '</label> ' .
                        '<input id="author" name="author" type="text" value="' . esc_attr($user>display_name) . '" size="30"' . ($req ? ' ariarequired="true"' : '') . ' /></div>',
                    'email' => '<div class="commentformemail"><label for="email">Email ' . ($req ? '<span class="required"></span>' : '') . '</label> ' .
                        '<input id="email" name="email" type="text" value="' . esc_attr($user>user_email) . '" size="30"' . ($req ? ' ariarequired="true"' : '') . ' /></div>',
                    'url' => '<div class="commentformurl"><label for="url">Website</label>' .
                        '<input id="url" name="url" type="text" value="' . esc_attr($user>user_url) . '" size="30" /></div>',
                )),
                'comment_notes_after' => '',
                'title_reply' => '',
                'title_reply_to' => __('Leave a Reply to %s', 'yourtheme'),
                'logged_in_as' => '<p class="loggedinas">' . sprintf(__('Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>', 'yourtheme'), admin_url('profile.php'), $user>display_name, wp_logout_url(apply_filters('the_permalink', get_permalink()))) . '</p>',
                'comment_notes_before' => '',
                'label_submit' => 'Post Comment',
            );

            // 输出评论编辑器
            comment_form($comment_args);
            ?>

        </form>

    <?php endif; // 如果不需要登录,显示评论表单
    ?>

</div>

<?php endif; // 如果评论开启,显示评论表单
?>

在上面的示例中,我们使用了wp_editor函数来生成评论框。评论框的样式和其他HTML结构可以根据你的主题进行自定义。此外,你还可以根据需要调整评论表单的字段,以满足你的需求。

有用0
  • 2023.11.09初次和大家见面了!

等待您对该主题的建议

发表评论

还能输入240个字

Hi, 欢迎加入Wordpress技术交流群,带你装逼带你飞!

我要入群
也想出现在这里?联系我们
wordpress加速

我来推荐一个更牛逼的给你看看?

  • 猛戳我吧