Last active
August 29, 2015 14:00
-
-
Save robneu/11106902 to your computer and use it in GitHub Desktop.
How to add comment numbering to a WordPress theme using Greg's Threaded Comment Numbering plugin. Includes support for Genesis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Greg's Threaded Comment Numbering Genesis | |
--------------------------------------------- */ | |
.commentnumber { | |
display: block; | |
float: right; | |
font-size: 40px; | |
font-size: 4rem; | |
margin-left: 20px; | |
margin-left: 2rem; | |
padding: 0 20px; | |
padding: 0 2rem; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'genesis_comment_list_args', 'prefix_numbered_comment_filter' ); | |
/** | |
* Integrate Greg's Threaded Comment Numbering plugin by overriding | |
* the default Genesis comment callback function. | |
* | |
* @param $args Default genesis comment args. | |
* @return $args Modifed comment args with new callback function. | |
* | |
* @copyright Copyright (c) 2014, FAT Media, LLC | |
*/ | |
function prefix_numbered_comment_filter( $args ) { | |
if ( ! function_exists( 'gtcn_comment_numbering' ) ) { | |
return $args; | |
} | |
$args['callback'] = 'prefix_numbered_comment_callback'; | |
return $args; | |
} | |
/** | |
* Comment callback for {@link genesis_default_list_comments()} if HTML5 is active. | |
* | |
* Does `genesis_before_comment` and `genesis_after_comment` actions. | |
* | |
* Applies `comment_author_says_text` and `genesis_comment_awaiting_moderation` filters. | |
* | |
* @since 2.0.0 | |
* | |
* @param stdClass $comment Comment object. | |
* @param array $args Comment args. | |
* @param integer $depth Depth of current comment. | |
*/ | |
function prefix_numbered_comment_callback( $comment, array $args, $depth ) { | |
$GLOBALS['comment'] = $comment; ?> | |
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>"> | |
<article <?php echo genesis_attr( 'comment' ); ?>> | |
<?php do_action( 'genesis_before_comment' ); ?> | |
<?php echo gtcn_comment_numbering( $comment->comment_ID, $args ); ?> | |
<header class="comment-header"> | |
<p <?php echo genesis_attr( 'comment-author' ); ?>> | |
<?php | |
echo get_avatar( $comment, $args['avatar_size'] ); | |
$author = get_comment_author(); | |
$url = get_comment_author_url(); | |
if ( ! empty( $url ) && 'http://' !== $url ) { | |
$author = sprintf( '<a href="%s" rel="external nofollow" itemprop="url">%s</a>', esc_url( $url ), $author ); | |
} | |
printf( '<span itemprop="name">%s</span> <span class="says">%s</span>', $author, apply_filters( 'comment_author_says_text', __( 'says', 'theme-textdomain' ) ) ); | |
?> | |
</p> | |
<p class="comment-meta"> | |
<?php | |
$pattern = '<time itemprop="commentTime" datetime="%s"><a href="%s" itemprop="url">%s %s %s</a></time>'; | |
printf( $pattern, esc_attr( get_comment_time( 'c' ) ), esc_url( get_comment_link( $comment->comment_ID ) ), esc_html( get_comment_date() ), __( 'at', 'theme-textdomain' ), esc_html( get_comment_time() ) ); | |
edit_comment_link( __( '(Edit)', 'theme-textdomain' ), ' ' ); | |
?> | |
</p> | |
</header> | |
<div class="comment-content" itemprop="commentText"> | |
<?php if ( ! $comment->comment_approved ) : ?> | |
<p class="alert"><?php echo apply_filters( 'genesis_comment_awaiting_moderation', __( 'Your comment is awaiting moderation.', 'theme-textdomain' ) ); ?></p> | |
<?php endif; ?> | |
<?php comment_text(); ?> | |
</div> | |
<?php | |
comment_reply_link( array_merge( $args, array( | |
'depth' => $depth, | |
'before' => '<div class="comment-reply">', | |
'after' => '</div>', | |
) ) ); | |
?> | |
<?php do_action( 'genesis_after_comment' ); ?> | |
</article> | |
<?php | |
//* No ending </li> tag because of comment threading | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The template for displaying Comments | |
* | |
* The area of the page that contains comments and the comment form. | |
* | |
* @package WordPress | |
* @subpackage Twenty_Fourteen | |
* @since Twenty Fourteen 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 if ( have_comments() ) : ?> | |
<h2 class="comments-title"> | |
<?php | |
printf( _n( 'One thought on “%2$s”', '%1$s thoughts on “%2$s”', get_comments_number(), 'twentyfourteen' ), | |
number_format_i18n( get_comments_number() ), get_the_title() ); | |
?> | |
</h2> | |
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?> | |
<nav id="comment-nav-above" class="navigation comment-navigation" role="navigation"> | |
<h1 class="screen-reader-text"><?php _e( 'Comment navigation', 'twentyfourteen' ); ?></h1> | |
<div class="nav-previous"><?php previous_comments_link( __( '← Older Comments', 'twentyfourteen' ) ); ?></div> | |
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments →', 'twentyfourteen' ) ); ?></div> | |
</nav><!-- #comment-nav-above --> | |
<?php endif; // Check for comment navigation. ?> | |
<ol class="comment-list"> | |
<?php | |
$callback = null; | |
if ( function_exists('gtcn_basic_callback') ) { | |
$callback = 'gtcn_basic_callback'; | |
} | |
wp_list_comments( array( | |
'style' => 'ol', | |
'short_ping' => true, | |
'avatar_size'=> 34, | |
'callback' => $callback, | |
) ); | |
?> | |
</ol><!-- .comment-list --> | |
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?> | |
<nav id="comment-nav-below" class="navigation comment-navigation" role="navigation"> | |
<h1 class="screen-reader-text"><?php _e( 'Comment navigation', 'twentyfourteen' ); ?></h1> | |
<div class="nav-previous"><?php previous_comments_link( __( '← Older Comments', 'twentyfourteen' ) ); ?></div> | |
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments →', 'twentyfourteen' ) ); ?></div> | |
</nav><!-- #comment-nav-below --> | |
<?php endif; // Check for comment navigation. ?> | |
<?php if ( ! comments_open() ) : ?> | |
<p class="no-comments"><?php _e( 'Comments are closed.', 'twentyfourteen' ); ?></p> | |
<?php endif; ?> | |
<?php endif; // have_comments() ?> | |
<?php comment_form(); ?> | |
</div><!-- #comments --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Greg's Threaded Comment Numbering | |
--------------------------------------------- */ | |
.commentnumber { | |
display: block; | |
float: right; | |
font-size: 40px; | |
margin-left: 20px; | |
padding: 0 20px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The template for displaying Comments | |
* | |
* The area of the page that contains comments and the comment form. | |
* | |
* @package WordPress | |
* @subpackage Twenty_Fourteen | |
* @since Twenty Fourteen 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 if ( have_comments() ) : ?> | |
<h2 class="comments-title"> | |
<?php | |
printf( _n( 'One thought on “%2$s”', '%1$s thoughts on “%2$s”', get_comments_number(), 'twentyfourteen' ), | |
number_format_i18n( get_comments_number() ), get_the_title() ); | |
?> | |
</h2> | |
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?> | |
<nav id="comment-nav-above" class="navigation comment-navigation" role="navigation"> | |
<h1 class="screen-reader-text"><?php _e( 'Comment navigation', 'twentyfourteen' ); ?></h1> | |
<div class="nav-previous"><?php previous_comments_link( __( '← Older Comments', 'twentyfourteen' ) ); ?></div> | |
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments →', 'twentyfourteen' ) ); ?></div> | |
</nav><!-- #comment-nav-above --> | |
<?php endif; // Check for comment navigation. ?> | |
<ol class="comment-list"> | |
<?php | |
wp_list_comments( array( | |
'style' => 'ol', | |
'short_ping' => true, | |
'avatar_size'=> 34, | |
) ); | |
?> | |
</ol><!-- .comment-list --> | |
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?> | |
<nav id="comment-nav-below" class="navigation comment-navigation" role="navigation"> | |
<h1 class="screen-reader-text"><?php _e( 'Comment navigation', 'twentyfourteen' ); ?></h1> | |
<div class="nav-previous"><?php previous_comments_link( __( '← Older Comments', 'twentyfourteen' ) ); ?></div> | |
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments →', 'twentyfourteen' ) ); ?></div> | |
</nav><!-- #comment-nav-below --> | |
<?php endif; // Check for comment navigation. ?> | |
<?php if ( ! comments_open() ) : ?> | |
<p class="no-comments"><?php _e( 'Comments are closed.', 'twentyfourteen' ); ?></p> | |
<?php endif; ?> | |
<?php endif; // have_comments() ?> | |
<?php comment_form(); ?> | |
</div><!-- #comments --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We've also posted a tutorial explaining this code as well as a full review of Greg's Threaded Comment Numbering over on WP Bacon.