【问题标题】:wordpress comment form stylingwordpress 评论表单样式
【发布时间】:2015-03-06 01:36:54
【问题描述】:

我已将 HTML 模板集成到 Wordpress 主题中。在,菜单区有一个菜单叫做博客。单击该菜单时,我想显示所有帖子。单击某些特定帖子标题时,应该转到单个帖子的页面。在该页面上应该显示某些人较早发布的 cmets,以及可以通过该评论表对该帖子发表评论。

下面是我的 blog.php 代码

    <?php
/*
Template Name: Blog
*/
?>
<?php get_header(); ?>
        <div id="inner_contant">
            <div id="all_post">
                <?php
                    $myposts = get_posts('');
                    foreach($myposts as $post) :
                    setup_postdata($post);
                ?>
                <h2><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                <div class="author">Posted by <?php the_author(); ?></div>
                <div class="post_excerpt"><?php the_excerpt(); ?></div>
                <?php endforeach; wp_reset_postdata(); ?>
            </div>
        </div>
<?php get_footer(); ?>

下面是我的 single.php 代码

    <?php
/*
* The template for displaying all single posts and attachments
*/
?>
<?php get_header(); ?>
<div id="single_post_wrap">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <div class="time_and_author"><?php the_time('F jS, Y') ?> by <?php the_author() ?></div>
    <div class="post_content"><?php the_content(); ?></div>
    <p>Posted in <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    <?php endwhile; endif; ?>
        <?php  foreach (get_comments() as $comment): ?>
        <div><?php echo $comment->comment_author; ?> said: "<?php echo $comment->comment_content; ?>".</div>
        <?php endforeach; ?>
    <?php comments_template(); ?>    
</div>
</div>
<?php get_footer(); ?>

下面是我的 cmets.php 代码

    <?php $comment_args = array(
            'comment_notes_after' => '',
            'title_reply' => 'Have something to say?'
        ) ?>
<?php comment_form($comment_args); ?>

我想为该评论表单添加一些样式。我已经尝试了每件事,但对我没有用。提前感谢那些会帮助我的人。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    WordPress' comment_form function 打印一个带有 id 'commentform' 的表单。所以你可以使用 CSS 来设置这个表单的样式。

    form#commentform {
        // your styles.
    }
    
    form#commentform input {
        // your styles for inputs
    }
    
    /* default class of submit button is 'submit'. For changing it: add a
    * key=>value to comment_form args like 
    * 'class_submit' => 'your_submit_class'
    */
    form#commentform .submit {
        // your submit button styles.
    }
    

    另外,您可以像这样更改评论表单的 ID:

    <?php $comment_args = array(
        'comment_notes_after' => '',
        'title_reply' => 'Have something to say?',
        'id_form' => 'myAwesomeCommentForm'
    ) ?>
    <?php comment_form($comment_args); ?>
    

    【讨论】:

    • 谢谢@mht。我一直在为此努力一整天。这对我有很大帮助。再次感谢。
    • 抱歉造成不必要的争议,但为什么我看不到绿色勾号?
    • 谢谢@mht。我是stackoverflow的新手。所以,熟悉它需要一些时间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-08
    • 2013-07-27
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    相关资源
    最近更新 更多