[wp-trac] [WordPress Trac] #31282: finally introduce comments templating
WordPress Trac
noreply at wordpress.org
Wed Feb 11 00:18:22 UTC 2015
#31282: finally introduce comments templating
-------------------------+------------------------------
Reporter: ageibert | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Comments | Version: 4.1
Severity: normal | Resolution:
Keywords: | Focuses:
-------------------------+------------------------------
Comment (by F J Kaiser):
> [...] but the comments themself must be templated in a callback function
Just a short clarification: The callback will not be used if there is
''no'' `walker` argument set (i.e. a custom Comment Walker class) as the
callback is only used inside `Walker_Comment::start_el`. From 4.1.:
{{{#!php
if ( !empty( $args['callback'] ) ) {
ob_start();
call_user_func( $args['callback'], $comment, $args, $depth );
$output .= ob_get_clean();
return;
}
}}}
A custom walker doesn't have to implement it. The same goes for the `end-
callback` argument/callback.
I didn't test this, but I assume that you could load a template part
there, using `get_template_part()`. Example:
{{{#!php
// 'callback' => 'getCommentTemplatePart',
function getCommentTemplatePart( $comment, $args, $depth )
{
// Make `$comment`, `$args` & `$depth` available in the template
set_query_var( 'comment', $comment );
set_query_var( 'args', $args );
set_query_var( 'depth', $depth );
// load ~/wp-content/your-theme/parts/comment-post.php
get_template_part( 'parts/comment', 'post' );
}
// Inside parts/comment-post.php then just use `$comment`, `$args` and
`$depth`
}}}
Above is untested and I'm not sure if it works, but you should give it a
try. You can do the same thing for `end-callback` in case you really need
it.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/31282#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list