首页 问答 正文

如何在wordpress主题中实现留言板功能?

注册会员 / 悠然自学 / 2023-07-11/ 浏览 129 次

在WordPress主题中实现留言板功能,可以通过以下步骤来实现:

第1步:创建一个自定义页面模板(例如,filename为'custom-comments.php'),并将以下代码插入其中:

<?php
/*
* Template Name: Custom Comments
*/

get_header(); // 获取头部

if ( have_posts() ) :
  while ( have_posts() ) : the_post();

    the_content(); // 显示页面内容

    // 显示留言板表单
    comment_form();

    // 显示已有留言
    $comments_args = array(
      'walker' => null,
      'max_depth' => '',
      'style' => 'ol',
      'callback' => null,
      'end-callback' => null,
      'type' => 'all',
      'reply_text' => '回复',
      'page' => '',
      'per_page' => '',
      'avatar_size' => 32,
      'reverse_top_level' => null,
      'reverse_children' => '',
      'format' => 'html5',
      'short_ping' => false,
      'echo' => true
    );
    wp_list_comments( $comments_args );

  endwhile;
endif;

get_footer(); // 获取底部
?> 

第2步:创建一个新页面,并在页面模板中选择刚刚创建的自定义页面模板'Custom Comments'。

第3步:通过WordPress的后台设置来允许留言。请确保在wp-admin -> 设置 -> 讨论中,选中了“允许读者在这个站点上发表评论”选项。

完成上述步骤后,你的WordPress主题就会有留言板功能了。用户可以在创建的页面上留下评论,并查看其他用户的留言。

大家谈论
    我的见解