Le formulaire de commentaire ne s'affiche pas correctement?

4

Je souhaite afficher le formulaire de commentaire dans la page de mon blog comment_form() , mais son affichage est similaire à celui-ci:

  

Commentaire

     

nom

     

email

     

site web

Mais ce formulaire devrait être affiché comme ça

  

Nom

     

email

     

site web

     

commentaire

J'ai essayé la plupart des démos et des extraits, mais ils ne sont pas travaillés. Donc, tout le monde a une idée à ce sujet.

Voici mon comments.php

    <?php
/**
 * @package WordPress
 * @subpackage XXXXX
 * @since Claster 1.0
 * 
 * Comments Template
 * Created by CMSMasters
 * 
 */


if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) {
    die(__('Please do not load this page directly. Thanks!', 'cmsmasters'));
}

if (post_password_required()) { 
    echo '<p class="nocomments">' . __('This post is password protected. Enter the password to view comments.', 'cmsmasters') . '</p>';

    return;
}

if (have_comments()) {
    echo '<aside id="comments">' . "\n" . 
        '<h6>';

    comments_number(__('No Comments', 'cmsmasters'), __('Comment', 'cmsmasters') . ' (1)', __('Comments', 'cmsmasters') . ' (%)');

    echo '</h6>' . "\n";

    if (get_previous_comments_link() || get_next_comments_link()) {
        echo '<aside class="project_navi" role="navigation">' . "\n\t" . 
            '<span class="fl">' . "\n\t\t";

        previous_comments_link('&larr; ' . __('Older Comments', 'cmsmasters'));

        echo "\n\t" . '</span>' . "\n\t" . 
        '<span class="fr">' . "\n\t\t";

        next_comments_link(__('Newer Comments', 'cmsmasters') . ' &rarr;');

        echo "\n\t" . '</span>' . "\r" . 
        '</aside>' . "\n";
    }

    echo '<ol class="commentlist">' . "\n";

    wp_list_comments(array( 
        'type' => 'comment', 
        'callback' => 'mytheme_comment' 
    ));

    echo '</ol>' . "\n";

    if (get_previous_comments_link() || get_next_comments_link()) {
        echo '<aside class="project_navi" role="navigation">' . "\n\t" . 
            '<span class="fl">' . "\n\t\t";

        previous_comments_link('&larr; ' . __('Older Comments', 'cmsmasters'));

        echo "\n\t" . '</span>' . "\n\t" . 
        '<span class="fr">' . "\n\t\t";

        next_comments_link(__('Newer Comments', 'cmsmasters') . ' &rarr;');

        echo "\n\t" . '</span>' . "\r" . 
        '</aside>' . "\n";
    }

    echo '</aside>';
}

if (comments_open()) {
    $form_fields =  array( 
        'author' => '<p class="comment-form-author">' . "\n" . 
            '<label for="author">' . __('Name', 'cmsmasters') . (($req) ? ' <span class="required color_3">*</span>' : '') . '</label>' . "\n" . 
            '<input type="text" id="author" name="author" value="' . esc_attr($commenter['comment_author']) . '" size="30"' . ((isset($aria_req)) ? $aria_req : '') . ' />' . "\n" . 
        '</p>' . "\n", 
        'email' => '<p class="comment-form-email">' . "\n" . 
            '<label for="email">' . __('Email', 'cmsmasters') . (($req) ? ' <span class="required color_3">*</span>' : '') . '</label>' . "\n" . 
            '<input type="text" id="email" name="email" value="' . esc_attr($commenter['comment_author_email']) . '" size="30"' . ((isset($aria_req)) ? $aria_req : '') . ' />' . "\n" . 
        '</p>' . "\n", 
        'url' => '<p class="comment-form-url">' . "\n" . 
            '<label for="url">' . __('Website', 'cmsmasters') . '</label>' . "\n" . 
            '<input type="text" id="url" name="url" value="' . esc_attr($commenter['comment_author_url']) . '" size="30" />' . "\n" . 
        '</p>' . "\n" 
    );

    echo "\n\n";

    comment_form(array( 
        'fields' => apply_filters('comment_form_default_fields', $form_fields), 
        'comment_field' => '<p class="comment-form-comment">' . 
            '<textarea name="comment" id="comment" cols="28" rows="6"></textarea>' . 
        '</p>', 
        'must_log_in' => '<p class="must-log-in">' . __('You must be', 'cmsmasters') . ' <a href="' . wp_login_url(apply_filters('the_permalink', get_permalink())) . '">' . __('logged in', 'cmsmasters') . '</a> ' . __('to post a comment', 'cmsmasters') . '.</p>' . "\n", 
        'logged_in_as' => '<p class="logged-in-as">' . __('Logged in as', 'cmsmasters') . ' <a href="' . admin_url('profile.php') . '">' . $user_identity . '</a>. <a class="all" href="' . wp_logout_url(apply_filters('the_permalink', get_permalink())) . '" title="' . __('Log out of this account', 'cmsmasters') . '">' . __('Log out?', 'cmsmasters') . '</a></p>' . "\n", 
        'comment_notes_before' => '<p class="comment-notes">' . __('Your email address will not be published. Required fields are marked', 'cmsmasters') . ' <span class="required color_3">*</span></p>' . "\n", 
        'comment_notes_after' => '', 
        'id_form' => 'commentform', 
        'id_submit' => 'submit', 
        'title_reply' => __('Leave a Reply', 'cmsmasters'), 
        'title_reply_to' => __('Leave your comment to', 'cmsmasters'), 
        'cancel_reply_link' => __('Cancel Reply', 'cmsmasters'), 
        'label_submit' => __('Submit Comment', 'cmsmasters') 
    ));
}
    
posée Mayank Vadiya 04.03.2016 - 14:04

1 réponse

5

Comment.php

La façon dont je vois votre comment.php semble compliquée et complexe, vous pouvez poster ce morceau de code dans votre comment.php et tout devrait bien se passer.

<?php 
/**
 * If the current post is protected by a password and
 * the visitor has not yet entered the password we will
 * return early without loading the commend
 */
if (post_password_required()) {
    return;
}

?>

    <?php

        // Do not delete these lines
        if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
        die ('Please do not load this page directly. Thanks!');
        ?>

        <!-- You can start editing here. -->
    <div id="comment-area">
        <?php if ( have_comments() ) : ?>

            <h4 class="comments">Comments <?php comments_number( '( 0 )', '<span class="responses">( 1 )</span>', '<span class="response">( % )</span>' ); ?></h4>

            <?php the_comments_navigation(); ?>

            <ol class="commentlist">
                <?php 
                wp_list_comments( array(
                    'callback'      => 'custom_comment_callback',
                    'style'         => 'ol',
                )); 
                ?>
            </ol>

            <?php the_comments_navigation(); ?>

    </div>

        <?php else : // this is displayed if there are no comments so far ?>

        <?php if ('open' == $post->comment_status) : ?>
        <!-- If comments are open, but there are no comments. -->

        <?php else : // comments are closed ?>
            <!-- If comments are closed. -->
            <p class="nocomments">Comments are closed.</p>

        <?php endif; ?>

        <?php endif; ?>

        <?php if ('open' == $post->comment_status) : ?>

            <div id="respond">

                <h4 class="comment-title">
                    <?php comment_form_title( 'Leave a Comment', 'Leave a Reply to %s' );?>
                </h4>

                <div class="cancel-comment-reply">
                    <small><?php cancel_comment_reply_link(); ?></small>
                </div>

        <?php if ( get_option('comment_registration') && !$user_ID ) : ?>
                <p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p>

        <?php else : ?>

            <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
                <?php if ( $user_ID ) : ?>

                    <p class="logged-in">Logged in as 
                        <span class="login-user"><?php echo $user_identity; ?></span>. 
                        <a href="<?php echo wp_logout_url(get_permalink()); ?>">Log out <i class="fa fa-angle-right"></i></a>
                    </p>

                <?php else : ?>

                    <p class="comment-form-author fa">
                        <input type="text" name="author" class="author" autocomplete="off" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> placeholder="Name"/>
                    </p>

                    <p class="comment-form-email fa">
                        <input type="email" name="email" class="email" autocomplete="off" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> placeholder="E-Mail"/>
                    </p>

                <?php endif; ?>

                <!--<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>-->

                    <p class="comment-form-comment fa">
                        <textarea name="comment" class="comment" rows="7" tabindex="3" placeholder="Comment"></textarea>
                    </p>

                    <p class="form-submit">
                        <input name="submit" type="submit" class="submit" tabindex="4" value="Post Comment" />
                        <?php comment_id_fields(); ?>
                    </p>
                <?php do_action('comment_form', $post->ID); ?>
            </form>

            <?php endif; // If registration required and not logged in ?>
        </div>

    <?php endif; // if you delete this the sky will fall on your head ?>

N'oubliez pas que ceci est sans l'entrée du site Web, mais il est facile de l'ajouter: D

Single.php

Dans votre fichier single.php , vous pouvez ajouter cette ligne de code pour vérifier si les commentaires sont ouverts, puis afficher le comment_template

.
<?php 
    if ( comments_open() || get_comments_number() ) {
        comments_template();
    }
?>
    
réponse donnée Stephen 04.03.2016 - 14:41

Lire d'autres questions sur les étiquettes