Permalink
Browse files

first pass at modularizing comments

  • Loading branch information...
1 parent 4301c67 commit defd05dd89d16f55c9ad7b751015c4c9a1c2a7d4 @willnorris committed Jan 24, 2011
Showing with 93 additions and 78 deletions.
  1. +9 −35 comment.php
  2. +4 −0 comment/author.php
  3. +15 −0 comment/comment.php
  4. +10 −0 comment/meta.php
  5. +1 −0 comment/pingback.php
  6. +26 −43 comments.php
  7. +6 −0 comments/navigation.php
  8. +22 −0 functions.php
View
@@ -1,40 +1,14 @@
-<?php
- global $comment_args, $comment_depth;
-?>
<article <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
<?php
-
- switch ( $comment->comment_type ) :
- case '' :
- ?>
- <div class="author comment-author vcard">
- <?php echo get_avatar( $comment, 40 ); ?>
- <?php printf( __( '%s <span class="says">says:</span>', 'pdx' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
- </div><!-- .comment-author .vcard -->
- <?php if ( $comment->comment_approved == '0' ) : ?>
- <em><?php _e( 'Your comment is awaiting moderation.', 'pdx' ); ?></em>
- <br />
- <?php endif; ?>
-
- <div class="comment-meta"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><?php
- /* translators: 1: date, 2: time */
- printf( __( '%1$s at %2$s', 'pdx' ), get_comment_date(), get_comment_time() ); ?></a>
- <?php edit_comment_link( __( '(Edit)', 'pdx' ), ' ' ); ?>
- </div><!-- .comment-meta .commentmetadata -->
-
- <div class="comment-body"><?php comment_text(); ?></div>
-
- <div class="reply">
- <?php comment_reply_link( array_merge( $comment_args, array( 'depth' => $comment_depth, 'max_depth' => $comment_args['max_depth'] ) ) ); ?>
- </div><!-- .reply -->
-
- <?php
+ switch ( $comment->comment_type ) {
+ case '':
+ get_template_module( 'comment/comment' );
break;
- case 'pingback' :
- case 'trackback' :
- ?>
- <p><?php _e( 'Pingback:', 'pdx' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'pdx'), ' ' ); ?></p>
- <?php
+ case 'pingback':
+ case 'trackback':
+ get_template_module( 'comment/pingback' );
break;
- endswitch;
+ }
+
+ // closing </article> tag is handled by call to wp_list_comments()
?>
View
@@ -0,0 +1,4 @@
+ <div class="author comment-author vcard">
+ <?php echo get_avatar( $comment, 40 ); ?>
+ <?php printf( __( '%s <span class="says">says:</span>', 'pdx' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
+ </div><!-- .comment-author .vcard -->
View
@@ -0,0 +1,15 @@
+ <?php global $comment_args, $comment_depth; ?>
+ <?php get_template_module( 'comment/author' ); ?>
+
+ <?php if ( $comment->comment_approved == '0' ) : ?>
+ <em><?php _e( 'Your comment is awaiting moderation.', 'pdx' ); ?></em>
+ <br />
+ <?php endif; ?>
+
+ <?php get_template_module( 'comment/meta' ); ?>
+
+ <div class="comment-body"><?php comment_text(); ?></div>
+
+ <div class="reply">
+ <?php comment_reply_link( array_merge( $comment_args, array( 'depth' => $comment_depth, 'max_depth' => $comment_args['max_depth'] ) ) ); ?>
+ </div><!-- .reply -->
View
@@ -0,0 +1,10 @@
+ <div class="comment-meta"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><?php
+ printf( '<time datetime="%1$s" class="entry-date">%2$s</time>',
+ esc_attr( get_comment_time('c') ),
+ /* translators: 1: date, 2: time */
+ sprintf( __( '%1$s at %2$s', 'pdx' ), get_comment_date(), get_comment_time() )
+ );
+ ?></a>
+ <?php edit_comment_link( __( '(Edit)', 'pdx' ), ' ' ); ?>
+ </div><!-- .comment-meta -->
+
View
@@ -0,0 +1 @@
+ <p><?php _e( 'Pingback:', 'pdx' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'pdx'), ' ' ); ?></p>
View
@@ -1,48 +1,31 @@
-<?php if ( post_password_required() ): ?>
- <aside id="comments">
- <div class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'pdx' ); ?></div>
- </aside>
-<?php
- return;
-endif;
-?>
-
<aside id="comments">
-<?php if ( have_comments() ) : ?>
- <h3 id="comments-title"><?php comments_number(
- sprintf(__('No Responses to %s', 'pdx'), '<em>' . get_the_title() . '</em>'),
- sprintf(__('One Response to %s', 'pdx'), '<em>' . get_the_title() . '</em>'),
- sprintf(__('%% Responses to %s', 'pdx'), '<em>' . get_the_title() . '</em>')
- ); ?> </h3>
-
- <?php if ( get_comment_pages_count() > 1 ) : // are there comments to navigate through ?>
- <div class="navigation">
- <div class="nav-previous"><?php previous_comments_link( __('&larr; Older Comments', 'pdx') ); ?></div>
- <div class="nav-next"><?php next_comments_link( __('Newer Comments &rarr;', 'pdx') ); ?></div>
- </div>
- <?php endif; ?>
-
- <?php //wp_list_comments( array('callback' => 'pdx_comment_start', 'end-callback' => 'pdx_comment_end') ); ?>
- <?php wp_list_comments( array('style' => 'div', 'callback' => 'pdx_comment_start', 'end-callback' => 'pdx_comment_end') ); ?>
-
- <?php if ( get_comment_pages_count() > 1 ) : // are there comments to navigate through ?>
- <div class="navigation">
- <div class="nav-previous"><?php previous_comments_link( __('&larr; Older Comments', 'pdx') ); ?></div>
- <div class="nav-next"><?php next_comments_link( __('Newer Comments &rarr;', 'pdx') ); ?></div>
- </div>
+<?php if ( post_password_required() ): ?>
+ <div class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'pdx' ); ?></div>
+<?php else: ?>
+ <?php if ( have_comments() ) : ?>
+ <h3 id="comments-title"><?php pdx_comments_title(); ?></h3>
+ <?php if ( get_comment_pages_count() > 1 ) : ?>
+ <nav id="comment-nav-above" class="navigation">
+ <div class="nav-previous"><?php previous_comments_link( __('&larr; Older Comments', 'pdx') ); ?></div>
+ <div class="nav-next"><?php next_comments_link( __('Newer Comments &rarr;', 'pdx') ); ?></div>
+ </nav>
+ <?php endif; ?>
+
+ <?php pdx_list_comments(); ?>
+
+ <?php if ( get_comment_pages_count() > 1 ) : ?>
+ <nav id="comment-nav-above" class="navigation">
+ <div class="nav-previous"><?php previous_comments_link( __('&larr; Older Comments', 'pdx') ); ?></div>
+ <div class="nav-next"><?php next_comments_link( __('Newer Comments &rarr;', 'pdx') ); ?></div>
+ </nav>
+ <?php endif; ?>
+ <?php else : // no comments so far ?>
+ <?php if ( comments_open() ) : // comments are open, but there are no comments ?>
+ <?php else : // comments are closed ?>
+ <p class="nocomments"><?php _e('Comments are closed.', 'pdx'); ?></p>
+ <?php endif; ?>
<?php endif; ?>
-<?php else : // this is displayed if there are no comments so far ?>
-
- <?php if ( comments_open() ) : // If comments are open, but there are no comments ?>
-
- <?php else : // if comments are closed ?>
-
- <p class="nocomments"><?php _e('Comments are closed.', 'pdx'); ?></p>
-
- <?php endif; ?>
+ <?php comment_form(); ?>
<?php endif; ?>
-
-<?php comment_form(); ?>
-
</aside><!-- #comments -->
View
@@ -0,0 +1,6 @@
+ <?php if ( get_comment_pages_count() > 1 ) : ?>
+ <nav class="navigation">
+ <div class="nav-previous"><?php previous_comments_link( __('&larr; Older Comments', 'pdx') ); ?></div>
+ <div class="nav-next"><?php next_comments_link( __('Newer Comments &rarr;', 'pdx') ); ?></div>
+ </nav>
+ <?php endif; ?>
View
@@ -179,6 +179,22 @@ function pdx_archive_page_description() {
}
+function pdx_comments_title() {
+ comments_number(
+ sprintf(__('No Responses to %s', 'pdx'), '<em>' . get_the_title() . '</em>'),
+ sprintf(__('One Response to %s', 'pdx'), '<em>' . get_the_title() . '</em>'),
+ sprintf(__('%% Responses to %s', 'pdx'), '<em>' . get_the_title() . '</em>')
+ );
+}
+
+
+function pdx_list_comments() {
+ wp_list_comments(
+ array( 'style' => 'div', 'callback' => 'pdx_comment_start', 'end-callback' => 'pdx_comment_end')
+ );
+}
+
+
/**
* Cleanup a few core WordPress things.
*/
@@ -207,6 +223,9 @@ function pdx_cleanup_wp() {
add_action('wp', 'pdx_cleanup_wp', 99);
+/**
+ * Start 'comment' template module.
+ */
function pdx_comment_start( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
$GLOBALS['comment_args'] = $args;
@@ -216,6 +235,9 @@ function pdx_comment_start( $comment, $args, $depth ) {
}
+/**
+ * End 'comment' template module.
+ */
function pdx_comment_end( $comment, $args, $depth ) {
?>
</article>

0 comments on commit defd05d

Please sign in to comment.