Thread Starter
wcten
(@wcten)
Oh, by the way, how do I add pagination to it? Thanks.
Thread Starter
wcten
(@wcten)
I got this done!
But it shows the full comments.
How do I get the comments excerpt?
<?php
/*
Template Name: Author Comments Template
*/
?>
<?php get_header(); ?>
<div class="content-wrap">
<div class="content">
<?php tie_breadcrumbs() ?>
<div id="content" role="main">
<?php
# The comment functions use the query var 'cpage', so we'll ensure that's set
$page = intval( get_query_var( 'cpage' ) );
if ( 0 == $page ) {
$page = 1;
set_query_var( 'cpage', $page );
}
# We'll do 10 comments per page...
# Note that the 'page_comments' option in /wp-admin/options-discussion.php must be checked
$comments_per_page = 10;
$comments = get_comments( array( 'user_id' => '1', 'status' => 'approve' ) );
?>
<ol start="<?php echo $comments_per_page * $page - $comments_per_page + 1 ?>">
<?php wp_list_comments( array (
'style' => 'ol',
'per_page' => $comments_per_page,
'page' => $page,
'reverse_top_level' => false
), $comments ); ?>
</ol>
<?php # Now you can either use paginate_comments_links ... ?>
<?php paginate_comments_links() ?>
<?php # Or you can next/prev yourself... ?>
<?php if ( get_comment_pages_count( $comment, $comments_per_page ) > 1 ) : // are there comments to navigate through ?>
<nav id="comment-nav">
<div class="nav-previous"><?php previous_comments_link( __( '← Newer Comments' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Older Comments →' ) ); ?></div>
</nav>
<?php endif; ?>
</div>
</div><!-- .content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Extend the Walker_Comment class, modified to use comment_excerpt(). Pass your new walker object as a ‘walker’ argument in wp_list_comments()
Thread Starter
wcten
(@wcten)
Thanks a lot.
But I have absolutely no idea how to use the walker class. Can you please elaborate more. Thank you.
It’s not something easily answered here. If you do not understand the OOP concept of extending classes, try searching around for generic programming tutorials, preferably in PHP, but not necessarily WP.
This should help too: http://shinraholdings.com/621/custom-walker-to-extend-the-walker_comment-class/
The walker is responsible for “walking” down the comment hierarchy tree and outputting the content in an appropriate manner. Even if you don’t fully understand the Walker code, it’s OK. You just need to locate the function that outputs the actual comment content. Copy that function to your extended class and edit it to use comment_excerpt() instead of outputting the whole thing.
Then on the comment template, create a new object from your extended class and pass that object as the ‘walker’ argument to wp_list_comments().
Sorry I can’t be more explicit, I hope this helps some.