comments_template
The comments_template function is a function that calls the comment template. It is very simple to use. Like get_header() and other functions, it is an include file class function. Today we will talk about its use.
Description
As mentioned above, it is a function that calls the comment template.
Use
<?php comments_template( $file, $separate_comments ); ?>
Which
$file is the file name to be called. Default value: /comments.php
$separate_comments Whether to separate comments of different types Boolean Default value: false
It’s quite general, please read below for more details
Usage examples
<?php comments_template(get_post_format().'-comment.php', true ); ?>
In this way, you can display article comments according to your different article types.
Is the usage somewhat similar to get_template_part()?
As for the exact meaning of $separate_comments, I didn’t understand it, but the official default theme has always been true, so I followed up. I have researched it before, and it seems that the type referred to here means whether to reply or not.
wp_list_comments
The wp_list_comments function is a function that loops to output each comment of the current article or page. It is mainly used to output each comment in the WordPress theme, saving us the pain of manual convenience, and also making the WordPress comment function very good. Modular.
The wp_list_comments function can be used in combination with the comments_template function in the theme to separate the comment function of WordPress, and can better control the number of comment nesting levels, the number of comments displayed on each page, comment styles, etc. . So if you want to do a good job on the theme, then take a look.
Description
Original English text:
Displays all comments for a post or Page based on a variety of parameters including ones set in the administration area.
My understanding:
Use a globally set parameter to display all comments on an article or page.
Usage
<?php wp_list_comments( $args ); ?>
Parameter usage
<?php $args = array( 'walker' => null, 'max_depth' => , 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => , 'per_page' => , 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => ); ?>
$walker custom style class name
$avatar_size avatar size Default: 32
The $style comment container tag can be 'div', 'ol', or 'ul'. The default value is 'ul'. If not, you need to write it explicitly as follows.
<div class="commentlist"><?php wp_list_comments(array('style' => 'div')); ?></div>
or
<ol class="commentlist"><?php wp_list_comments(array('style' => 'ol')); ?></ol>
$type shows what kind of comments, parameters can be 'all', 'comment', 'trackback', 'pingback', 'pings'. 'pings' includes 'trackback' and 'pingback'.
Default value: ‘all’
$reply_text The text value of the reply button. This is rarely used and will not be explained. Default value: ‘Reply’
$login_text The text value of the login button. This is rarely used and will not be explained. Default value: ‘Log in to Reply’
$callback The callback function for comment display, that is, the function name for displaying the comment topic
$end-callback should be the callback function after the loop ends. I have not tested it, so please explore it yourself.
$reverse_top_level Boolean value. If this parameter is set to true, the latest comment will be displayed first, and subsequent comments will be displayed according to the background settings.
$reverse_children Boolean value. If this parameter is set to true, the latest comment with child comments will be displayed first, and subsequent comments will be displayed according to the background settings.
Example
Here is a demo of comment display in the official default theme twentyeleven,
For specific other parameters, please refer to the above introduction to demonstrate and explore by yourself.
<ol class="commentlist"> <?php /* Loop through and list the comments. Tell wp_list_comments() * to use twentyeleven_comment() to format the comments. * If you want to overload this in a child theme then you can * define twentyeleven_comment() and that will be used instead. * See twentyeleven_comment() in twentyeleven/functions.php for more. */ wp_list_comments( array( 'callback' => 'twentyeleven_comment' ) ); //twentyeleven_comment 函数在主题文件 "twentyeleven/functions.php"中定义。 ?> </ol>