the template function as a callback argument of wp_list_comments
function, and the template function takes three args:$comment, $args, $depth
, like the template function that defined in the theme twentyeleven
‘s functions.php,
function twentyeleven_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p>
<?php
/** and more ... **/
I want to invoke this function in another place, and I have the $comment
reference to a comment, but I don’t know how to set the $args
and $depth
variables. I know the value of $depth
or $args
can be changed in the admin settings, so, I can’t just set $depth
to 5 or whatever a number.
How can I get the $args
and $depth
???
Thanks in advance.
Just go ahead and call it in the same way the tventyeleven does:
wp_list_comments function will manage $depth and other $args itself (in walker). See source code of wp_list_comments and the walker using callback arg
Well, I have the solution.
first, use the global variable $comment_depth, pass it to
twentyeleven_comment()
function, and in thetwentyeleven_comment()
function, define a new variable named$defaults
like this:In another function, invoke
twentyeleven_comment()
function like this:I just want to output one comment by the
$comment_ID
ãthanks to those guys who have commented or answered 🙂
Be sure that ‘echo’ is true