【问题标题】:Customise Wordpress Comments Form自定义 Wordpress 评论表单
【发布时间】:2013-07-27 01:21:38
【问题描述】:

我正在尝试调整默认的 Wordpress cmets 表单,使其与 Foundation 框架一起工作。

这是我目前在functions.php 中使用的代码:

function pondera_comment_form() {
    $comment_args = array(
        'title_reply'=>'Have something to say?',
        'fields' => apply_filters( 'comment_form_default_fields',
        array(
            'author' => '<div class="small-12 large-6 columns">' . '<label for="author">' . __( 'First Name' ) . '</label> ' . ( $req ? '<span>*</span>' : '' ) . '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></div>',
            'email'  => '<div class="small-12 large-6 columns">' . '<label for="email">' . __( 'Email Address' ) . '</label> ' . ( $req ? '<span>*</span>' : '' ) . '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' />'.'</div>',
            'url'    => '' )
        ),
        'comment_field' => 
        '<div class="small-12 large-12 columns">' . '<label for="comment">' . __( 'Comments' ) . '</label>' . '<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>' .  '</div>',
        'comment_notes_before' => '',
        'comment_notes_after' => '',
    );
    comment_form($comment_args);
}

我正在寻找一种方法来自定义提交按钮,其方式与其他一些输入相同,但我不确定如何执行此操作。我想将它包装在这个&lt;div class="small-12 columns&gt; 中,并将.button 类添加到输入本身。

我也希望为 WP 生成的 &lt;h3&gt; 标题做同样的事情。

【问题讨论】:

  • 您的主题中没有 cmets.php 文件吗?如果是这样,那么您可以通过向按钮添加任何您想要的类来直接修改表单,使其样式像基础。我一直都这样修改评论表。然而,这将取决于您的主题是如何设置的。
  • 我正在从头开始创建主题,因此我几乎可以使用任何方法。我确实有一个 cmets.php 文件,目前它概述了 cmets 本身的显示,然后有一个 &lt;?php pondera_comment_form(); ?&gt; 引用来显示表单。 (这就是我一直这样做的方式。)然后我使用该功能来调整功能。我没有意识到您可以从头开始编写所有代码,是否有资源页面显示如何正确执行此操作?
  • 我建议您检查白板框架。 whiteboardframework.com 写这个主题的人有一个非常好的 cmets.php 模板,显示了我建议的方法,也许这是一个很好的例子,如果它让你更接近你想要的地方,请告诉我们。祝你好运。
  • 谢谢指点,我去看看。

标签: wordpress wordpress-theming


【解决方案1】:

好的,我已经意识到在comments.php 中这是多么容易。非常感谢@sulfureous 为我指明了正确的方向。

对于任何感兴趣的人,这是我放在comments.php 中的代码(最初引用的函数随后被删除):

<div class="row">
    <div class="large-12 columns">
        <?php if(comments_open()) : ?>
            <h3>Have something to say?</h3>
            <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="comments-form">
                <div class="row">
                    <div class="small-12 large-6 columns">
                        <label for="author"><?php _e('Name'); ?> <?php if($req) echo "(required)"; ?></label>
                        <input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" />
                    </div>
                    <div class="small-12 large-6 columns">
                        <label for="email"><?php _e('Email'); ?> <?php if($req) echo "(required)"; ?></label>
                        <input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" />
                    </div>
                </div>
                <div class="row">
                    <div class="small-12 columns">
                        <label for="comment"><?php _e('Comment'); ?></label>
                        <textarea name="comment" id="comment" cols="100%" rows="10" tabindex="3"></textarea>
                    </div>
                </div>
                <div class="row">
                    <div class="small-12 columns">
                        <input name="submit" type="submit" id="submit" tabindex="4" class="btn" value="Post Comment" />
                        <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
                    </div>
                </div>
                <?php do_action('comment_form', $post->ID); ?>
            </form>
        <?php else : ?>
            <h5><?php _e('Sorry, the comments are now closed.'); ?></h5>
        <?php endif; ?>
    </div>
</div>

【讨论】:

    猜你喜欢
    • 2012-02-01
    • 2013-11-27
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多