comments_template #47

Closed
apsolut opened this Issue Nov 6, 2012 · 8 comments

Projects

None yet

4 participants

@apsolut
apsolut commented Nov 6, 2012

why im having problems when i put comments_template into template ?

when user post comment i get stuck on blank screen of website/wp-comments-post.php

?

@jordanboston

Not sure if it will help, but I had to add a comments.php template to the theme.

"A WordPress Theme without comments.php is deprecated since version 3.0 with no alternative available."

@drewsymo
Owner

Hi @jordanboston

What did you put in your comments.php, out of curiosity?

@apsolut
apsolut commented Feb 17, 2013

I just have working version of comments.php -

<p class="nocomments"><?php _e('This post is password protected. Enter the password to view comments.', 'kubrick'); ?></p>
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses');?> <?php printf('to “%s”', the_title('', '', false)); ?></h3>
    <div class="navigation">
        <div class="alignleft"><?php previous_comments_link() ?></div>
        <div class="alignright"><?php next_comments_link() ?></div>
    </div>
<ol class="commentlist">
 <?php
 wp_list_comments(array(
  // see http://codex.wordpress.org/Function_Reference/wp_list_comments
  // 'login_text'        => 'Login to reply',
  // 'callback'          => null,
  // 'end-callback'      => null,
  // 'type'              => 'all',
  // 'avatar_size'       => 32,
  // 'reverse_top_level' => null,
  // 'reverse_children'  =>
  ));
  ?>
</ol>
    <div class="navigation">
        <div class="alignleft"><?php previous_comments_link() ?></div>
        <div class="alignright"><?php next_comments_link() ?></div>
    </div>
<?php
if ( ! comments_open() ) : // There are comments but comments are now closed
    echo"<p class='nocomments'>Comments are closed.</p>";
endif;

else : // I.E. There are no Comments
if ( comments_open() ) : // Comments are open, but there are none yet
// echo"

Be the first to write a comment.

";
else : // comments are closed
echo"

Comments are closed.

";
endif;
endif;

// Display Form/Login info Section
// the comment_form() function handles this and can be used without any paramaters simply as "comment_form()"
comment_form(array(
// see codex http://codex.wordpress.org/Function_Reference/comment_form for default values
// tutorial here http://blogaliving.com/wordpress-adding-comment_form-theme/
'comment_field' => '

<textarea name="comment" id="comment" cols="58" rows="10" tabindex="4" aria-required="true"></textarea>

',
'label_submit' => 'Submit',
'comment_notes_after' => ''
));

?>

@jordanboston

I simply borrowed from the default WordPress TwentyTwelve or whatever it's called.

<?php
/**
 * The template for displaying Comments.
 *
 * The area of the page that contains both current comments
 * and the comment form. The actual display of comments is
 * handled by a callback to fws_comment() which is
 * located in the functions.php file.
 *
 * @package WordPress
 * @subpackage My WordPress Theme
 * @since My Theme 1.0
 */

/*
 * 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 comments.
 */
if ( post_password_required() )
    return;
?>

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

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

    <?php if ( have_comments() ) : ?>
        <h2 class="comments-title">

        </h2>

        <ol class="commentlist">
            <?php wp_list_comments( array( 'callback' => 'fws_comment', 'style' => 'ol' ) ); ?>
        </ol><!-- .commentlist -->

        <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
        <nav id="comment-nav-below" class="navigation" role="navigation">
            <h1 class="assistive-text section-heading"><?php _e( 'Comment navigation', 'fws' ); ?></h1>
            <div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments', 'fws' ) ); ?></div>
            <div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;', 'fws' ) ); ?></div>
        </nav>
        <?php endif; // check for comment navigation ?>

        <?php
        /* If there are no comments and comments are closed, let's leave a note.
         * But we only want the note on posts and pages that had comments in the first place.
         */
        if ( ! comments_open() && get_comments_number() ) : ?>
        <p class="nocomments"><?php _e( 'Comments are closed.' , 'fws' ); ?></p>
        <?php endif; ?>

    <?php endif; // have_comments() ?>

    <?php comment_form(); ?>

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

and then also call from the functions.php

/**
 * Comments template
 */

if ( ! function_exists( 'fws_comment' ) ) :

function fws_comment( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    switch ( $comment->comment_type ) :
        case 'pingback' :
        case 'trackback' :
        // Display trackbacks differently than normal comments.
    ?>
    <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
        <p><?php _e( 'Pingback:', 'fws' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'fws' ), '<span class="edit-link">', '</span>' ); ?></p>
    <?php
            break;
        default :
        // Proceed with normal comments.
        global $post;
    ?>
    <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
        <article id="comment-<?php comment_ID(); ?>" class="comment">
            <header class="comment-meta comment-author vcard">
                <?php
                    echo get_avatar( $comment, 44 );
                    printf( '<cite class="fn">%1$s %2$s</cite>',
                        get_comment_author_link(),
                        // If current post author is also comment author, make it known visually.
                        ( $comment->user_id === $post->post_author ) ? '<span> ' . __( '(Post author) ', 'fws' ) . '</span>' : ''
                    );
                    printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
                        esc_url( get_comment_link( $comment->comment_ID ) ),
                        get_comment_time( 'c' ),
                        /* translators: 1: date, 2: time */
                        sprintf( __( '%1$s at %2$s', 'fws' ), get_comment_date(), get_comment_time() )
                    );
                ?>
            </header><!-- .comment-meta -->

            <?php if ( '0' == $comment->comment_approved ) : ?>
                <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'fws' ); ?></p>
            <?php endif; ?>

            <section class="comment-content comment">
                <?php comment_text(); ?>
                <?php edit_comment_link( __( 'Edit', 'fws' ), '<p class="edit-link">', '</p>' ); ?>
            </section><!-- .comment-content -->

            <div class="reply">
                <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'fws' ), 'after' => ' <span>&darr;</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
            </div><!-- .reply -->
        </article><!-- #comment-## -->
    <?php
        break;
    endswitch; // end comment_type check
}
endif;

This worked for me without needing to do much of anything else and my comments form works fine.

@Shelob9
Contributor
Shelob9 commented Feb 17, 2013

I dd the same borrowing comments.php from twenty twelve. I had some issues with getting the right classes to style buttons. I ended up using jQuery to do it. I made a gist showing how, thaught it might help.

https://gist.github.com/Shelob9/4584258

@drewsymo
Owner

Hey guys,

Thanks for the feedback.

I'm going to work on a simple comments.php template within the week to rectify this issue.

Cheers!

@drewsymo drewsymo was assigned Feb 17, 2013
@drewsymo
Owner

Hey guys,

The v4.0 branch has a comments template. You can preview v4 here:
http://fwp.drewsymo.com/

@jordanboston

Nice work Drew.

@drewsymo drewsymo closed this Apr 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment