首页 视频课程 主题开发课程第02章、开发实例 WordPress入门实例:文章评论制件方法

WordPress入门实例:文章评论制件方法

2023-06-11 / 631阅

文章评论制件方法

WordPress是一款强大的博客系统,它提供了丰富的功能,包括文章评论制件。文章评论制件可以让读者在阅读文章时发表自己的评论,与其他读者交流想法和观点。

下面是文章评论制件的实现方法:

  1. 在WordPress后台设置中开启文章评论功能。

  2. 在WordPress主题中添加评论制件代码。

示例代码如下:

<!-- 评论表单 -->
<div id="respond" class="comment-respond">
    <h3 id="reply-title" class="comment-reply-title">发表评论 <small><a rel="nofollow" id="cancel-comment-reply-link" href="/post/1234/#respond" style="display:none;">取消回复</a></small></h3>

    <form action="WordPress提交评论的PHP文件地址" method="post" id="commentform" class="comment-form" novalidate="">
        <p class="comment-form-comment">
            <label for="comment">评论:</label>
            <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required="" placeholder="请输入评论内容"></textarea>
        </p>
        <p class="comment-form-author">
            <label for="author">昵称:</label>
            <input id="author" name="author" type="text" value="" size="30" aria-required="true" required="" placeholder="请输入您的昵称">
        </p>
        <p class="comment-form-email">
            <label for="email">电子邮件(必填):</label>
            <input id="email" name="email" type="email" value="" size="30" aria-required="true" required="" placeholder="请输入您的电子邮件">
        </p>
        <p class="comment-form-url">
            <label for="url">网站:</label>
            <input id="url" name="url" type="url" value="" size="30" placeholder="请输入您的网站">
        </p>
        <p class="form-submit">
            <input name="submit" type="submit" id="submit" class="submit" value="发表评论">
            <input type="hidden" name="comment_post_ID" value="1234" id="comment_post_ID">
            <input type="hidden" name="comment_parent" id="comment_parent" value="0">
        </p>
    </form>
</div>

<!-- 评论列表 -->
<div id="comments" class="comments-area">
    <h3 class="comments-title">评论(2)</h3>
    <ol class="comment-list">
        <!-- 循环输出评论 -->
        <li class="comment">
            <div class="comment-body">
                <div class="comment-author">
                    <img src="头像URL" class="avatar" width="48" height="48">
                    <cite class="fn">评论人昵称</cite>
                    <span class="says">说道:</span>
                </div>
                <div class="comment-content">
                    <p>评论内容</p>
                </div>
                <div class="comment-meta">
                    <a href="评论的详细页面链接"><time datetime="2022-01-01T00:00:00+08:00">2022年1月1日 下午8:00</time></a>
                    <span class="reply">
                        <a rel="nofollow" class="comment-reply-link" href="/post/1234/#respond">回复</a>
                    </span>
                </div>
            </div>
            <!-- 循环输出子评论 -->
            <ol class="children">
                <li class="comment">
                    <div class="comment-body">
                        <div class="comment-author">
                            <img src="头像URL" class="avatar" width="32" height="32">
                            <cite class="fn">评论人昵称</cite>
                            <span class="says">说道:</span>
                        </div>
                        <div class="comment-content">
                            <p>子评论内容</p>
                        </div>
                        <div class="comment-meta">
                            <a href="子评论的详细页面链接"><time datetime="2022-01-01T00:00:00+08:00">2022年1月1日 下午8:00</time></a>
                            <span class="reply">
                                <a rel="nofollow" class="comment-reply-link" href="/post/1234/#respond">回复</a>
                            </span>
                        </div>
                    </div>
                </li>
            </ol>
        </li>
    </ol>
</div> 

需要替换示例代码中以下内容:

  1. WordPress提交评论的PHP文件地址:指向处理评论信息的PHP文件地址。

  2. 1234:当前文章的ID。

  3. 头像URL:评论人的头像地址。

  4. 评论人昵称:评论人的昵称。

  5. 评论内容:评论内容。

  6. 子评论内容:子评论内容。

  7. 2022年1月1日 下午8:00:评论的时间。

  8. 评论的详细页面链接:详细的评论页面链接。

  9. 子评论的详细页面链接:详细的子评论页面链接。

注:代码仅供参考,具体实现需要根据实际需要进行修改。

以上就是WordPress文章评论制件的实现方法。通过添加评论制件,可以让读者与博主互动,促进交流和分享。

阅读文章或者观看视频过程中有任何问题,请下方留言或者联系我Q248758228

大家谈论
    我的见解
    目录