【问题标题】:WordPress - Twenty Thirteen - Leave a Reply (comment) - can this be edited?WordPress - 二十三 - 发表评论(评论) - 可以编辑吗?
【发布时间】:2016-09-08 14:47:27
【问题描述】:

我对@9​​87654323@ WordPress 主题底部的Leave a Reply 部分有疑问。在页面底部,您会看到询问您的姓名、电子邮件、网站的区域,然后是在评论中写下的选项。

我想知道是否可以将单词 Website 更改为 Agency。我查看了几个文件,但似乎无法在代码中找到该区域。我查看了Comments.php 以及content.php 文件。在content.php 文件的底部,我确实看到了我认为可能需要编辑但不确定如何进行此操作的部分。

这是我正在谈论的区域的屏幕截图。

【问题讨论】:

  • 当然可以。只需搜索该元素的 ID 并在 WordPress 编辑器中查找即可。

标签: wordpress


【解决方案1】:

@user2898224:

您要查找的文件是 WordPress 核心文件 'wp-includes\comment-template.php'。

您需要更改第 #2058 行,如下所示:

'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .

您所要做的就是在此行中将“网站”更改为“代理商”。

请记住,此更改会修改 WordPress 核心文件,因此,如果您想升级 WordPress 安装,则需要在升级后再次进行相同的更改。

修改 WordPress 核心文件也不是一个好主意,但在这种情况下,更改足够小,您可以侥幸逃脱。

如果您不想(也不应该)修改 WordPress 核心文件,您还可以执行以下操作:

在二十三主题的 'cmets.php' 文件中,将此调用替换为 comment_form 函数:

<?php comment_form(); ?>

有了这段代码(是的,所有这些代码都是必需的):

<?php           
    $fields = array(
        'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                        '<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' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                        '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
        'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Agency' ) . '</label> ' .
                        '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
    );

    $comments_args = array(
        'fields' =>  $fields
    );

    comment_form( $comments_args );
?>

这似乎是一种更复杂的方式来更改评论表单上的一个单词,但它可以防止您弄乱任何 WordPress 核心文件。

【讨论】:

  • 哇这么快的帮助。这正是我一直在寻找的。我在那个地区,确实看到了“网站”,但仍然有点不确定它是如何运作的。但是在阅读了每个人的答案后,我看到了。也不想对文件进行更改,所以这很完美。谢谢!
【解决方案2】:

在主题的 Comments.php 中,将无参数调用替换为 comment_form(在底部)。你可以在那里传递你的修改。无需修改核心。见comment_form API reference

【讨论】:

    【解决方案3】:

    您可以通过wordpress过滤器通过您主题的functions.php添加或修改评论表单字段。 尝试将此添加到您的functions.php

    function my_fields($fields) {
        // replace url with agency 
        $fields['url'] = '<p class="comment-form-agency"><label for="agency">' . __( 'Agency' ) . '</label> ' .
                         '<input id="agency" name="agency" type="text" value="" size="30" /></p>';
    return $fields;
    }
    add_filter('comment_form_default_fields','my_fields');
    

    或者您可以将代理输入添加为新字段

    function my_fields($fields) {
            $fields['agency'] = '<p class="comment-form-agency"><label for="agency">' . __( 'Agency' ) . '</label> ' .
                             '<input id="agency" name="agency" type="text" value="" size="30" /></p>';
        return $fields;
        }
        add_filter('comment_form_default_fields','my_fields');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-14
      • 2016-09-02
      相关资源
      最近更新 更多