【问题标题】:WordPress - Custom Comments - Parent / Nested ReplyWordPress - 自定义评论 - 父/嵌套回复
【发布时间】:2013-03-11 22:31:22
【问题描述】:

我正在制作自定义 WordPress 主题并编辑了 cmets.php,但我无法将 cmets 保存为对另一条评论的回复。我已经成功地将注释父 ID 显示为源代码中的隐藏值,但它并没有将其相应地保存在数据库中(相反,它总是将 comment_parent 保存为 0)。此外,由于某种原因,评论者 IP 地址也未保存(comment_author_IP 显示为“::1”)。这是我到目前为止的代码:

    <?php
    if ( post_password_required() )
        return;
?>

    <div id="comments" class="comments-area">

    <?php // You can start editing here -- including this comment!

    $fields = array(
    'author'               => '<p class="comment-form-author"><label for="author">' . __( 'Name', 'domainreference' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
    'email'                => '<p class="comment-form-email"><label for="email">' . __( 'Email', 'domainreference' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>'
    );

    $defaults = array(
    'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
    'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p><p class="comment-form-math"><label for="math">' . __( 'five plus two', 'domainreference' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="math" name="math" type="text" value="' . esc_attr( $commenter['math'] ) . '" size="30"' . $aria_req . ' /></p></p><input type=\'hidden\' name=\'comment_post_ID\' value=\'\' id=\'comment_post_ID\' /><input type=\'hidden\' name=\'comment_parent\' id=\'comment_parent\' value=\''.$comment_parent.'\' />',
    'must_log_in'          => '<p class="must-log-in">' .  sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '</p>',
    'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '</p>',
    'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published. Required fields are marked *' ) . ( $req ? $required_text : '' ) . '</p>',
    'comment_notes_after'  => '',
    'id_submit'            => 'submit',
    'title_reply'          => __( 'Leave a Reply' ),
    'title_reply_to'       => __( 'Leave a Reply to %s' ),
    'comment_form_title'       => __( 'Leave a Reply', 'Leave a Reply to %s' ),
    'cancel_reply_link'    => __( 'Cancel reply' ),
    'label_submit'         => __( 'Post Comment' )
    );

    comment_form($defaults);
    ?>

</div><!-- #comments .comments-area -->

【问题讨论】:

  • 遇到类似问题...您解决了吗?
  • @benedict_w,不,我没有。如果你这样做,请告诉我。

标签: wordpress wordpress-theming


【解决方案1】:

看起来this support thread 可能与此问题有关。不显式设置comment_parent 字段(也可能省略comment_post_ID 字段)可能会解决post parent ID 问题,因为WordPress 会自动添加这些隐藏字段。

至于 IP 异常,::1 是相当于 127.0.0.1 (localhost) 的 IPv6,如果您在本地安装了 WordPress,则这是您的 IP 地址。

【讨论】:

  • 感谢您让我知道 IP 问题(我确实在本地安装了 WordPress)。我尝试省略 comment_parent 和 comment_post_ID 字段,但得到了相同的结果(comment_parent 保存为 0)。我也试过把 在声明 $fields 变量之前(如 here 所述),但得到了相同的结果(comment_parent 保存为 0)。我不知道我做错了什么。
  • @Pamela 您是否在 WordPress 中启用了“启用线程(嵌套)cmets...”选项(在“讨论设置”管理页面上)?
  • @Pamela 抱歉,这就是我所拥有的 :( 我注意到你也在 WordPress stackexchange 上问过这个问题,所以希望有人能够在那里回答你。如果我有任何顿悟,我会一定要分享它们。
  • 谢谢,如果我弄明白了,我也会在这里分享。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-24
  • 2013-07-27
  • 2012-12-17
  • 2012-02-01
  • 2013-11-27
  • 1970-01-01
  • 2013-01-14
相关资源
最近更新 更多