-
-
Save tommcfarlin/083f9a1212b872015e38 to your computer and use it in GitHub Desktop.
[WordPress] Showing how to easily separate comments and pingbacks using separate callback functions.
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 | |
function acme_comment( $comment, $args, $depth ) { | |
$GLOBALS['comment'] = $comment; | |
extract( $args, EXTR_SKIP ); | |
?> | |
<div <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID(); ?>"> | |
<div class="comment-body" id="div-comment-<?php comment_ID(); ?>"> | |
<div class="comment-author vcard"> | |
<span class="avatar"> | |
<?php echo get_avatar( $comment, $args['avatar_size'] ); ?> | |
</span><!-- .avatar --> | |
<div class="comment-meta-wrapper"> | |
<span class="comment-meta"> | |
<?php printf( '<cite class="fn">%s</cite>', get_comment_author_link() ); ?> | |
<a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"> | |
<?php printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?> | |
</a> | |
<?php edit_comment_link( __( 'Edit' ), '<div class="comment-edit-link-wrapper">', '</div>' ); ?> | |
</span><!-- .comment-meta --> | |
</div><!-- .comment-meta-wrapper --> | |
</div><!-- .comment-author --> | |
<div class="comment-text"> | |
<?php if ( '0' === $comment->comment_approved ) { ?> | |
<div class="comment-moderation-notice"> | |
<em class="comment-awaiting-moderation"> | |
<?php _e( 'Your comment is awaiting moderation.' ); ?> | |
</em><!-- .comment-awaiting-moderation --> | |
</div><!-- .comment-moderation-notice --> | |
<?php } // end if ?> | |
<?php comment_text(); ?> | |
</div><!-- .comment-text --> | |
<div class="reply"> | |
<?php | |
comment_reply_link( | |
array_merge( | |
$args, | |
array( | |
'add_below' => 'comment', | |
'depth' => $depth, | |
'max_depth' => $args['max_depth'] | |
) | |
) | |
); | |
?> | |
</div><!-- .reply --> | |
</div><!-- .comment-body --> | |
</div><!-- #div-comment-<?php comment_ID(); ?>--> | |
<?php | |
} // end acme_comment |
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
<div id="comments" class="comments-area"> | |
<?php | |
/* Don't forget to check if comments are open | |
* or if there are comments to display. | |
*/ | |
?> | |
<h3 class="response-title"> | |
<?php | |
printf( | |
_n( | |
'One Comment', '%1$s Comments', | |
get_comments_number() | |
), | |
number_format_i18n( get_comments_number() ) | |
); | |
?> | |
</h3> | |
<div class="comment-list"> | |
<?php | |
wp_list_comments( | |
array( | |
'type' => 'comment', | |
'callback' => 'acme_comment', | |
'avatar_size'=> 100 | |
) | |
); | |
?> | |
</div><!-- .comment-list --> | |
<h3 class="response-title"> | |
Trackbacks and Pingbacks | |
</h3> | |
<div class="ping-list"> | |
<?php | |
wp_list_comments( | |
array( | |
'type' => 'pings', | |
'callback' => 'example_pings', | |
'avatar_size'=> 100 | |
) | |
); | |
?> | |
</div><!-- .ping-list --> | |
</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
<?php | |
function acme_pings( $comment, $args, $depth ) { | |
$GLOBALS['comment'] = $comment; | |
extract( $args, EXTR_SKIP ); | |
?> | |
<div <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID(); ?>"> | |
<div class="ping-body" id="div-ping-<?php comment_ID(); ?>"> | |
<div class="ping-author vcard"> | |
<div class="ping-meta-wrapper"> | |
<span class="ping-meta"> | |
<?php | |
printf( '<cite class="fn">%s</cite>', get_comment_author_link() ); | |
printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time() ); | |
?> | |
</span><!-- .ping-meta --> | |
</div><!-- .ping-meta-wrapper --> | |
</div><!-- .ping-author --> | |
<div class="ping-text"> | |
<?php comment_text(); ?> | |
</div><!-- .ping-text --> | |
</div><!-- .ping-body --> | |
</div><!-- #div-ping-<?php comment_ID(); ?>--> | |
<?php | |
} // end acme_pings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment