comments_templateThecomments_template function is a function that calls a comment template.It's easy to use,As with functions like get_header (),Is an include file class function,Let's talk about his use today.
As mentioned above,Is a function that calls the comment template.
<php comments_template ($file, $separate_comments);?>
$file The name of the file to call Default:/comments.php
$separate_comments whether to separate comments without type boolean default:false
More general,Please look deeper
<?php comments_template (get_post_format (). "-Comment.php", true);?>
In this way, you can display article comments based on your different article types.
Is it similar to get_template_part () in usage?
As for the exact meaning of $separate_comments,I didn't figure it out either,However, the official default theme has always been true, so I followed up.Researched once before,Looks like the type referred here means whether to reply.
wp_list_commentsThe wp_list_comments function is a function that loops through each comment on the current post or page.It is mainly used to output each comment in the wordpress theme.Save us the pain of manual convenience,It also modularizes the comment function of wordpress.
The combination of wp_list_comments function and comments_template function in the theme can well separate the wordpress comment functionAnd you can better control the number of comment nesting levels, the number of comments displayed per page, the comment style, and so on.So if i want to make a good theme,Then take a look.
displays all comments for a post or page based on a variety of parameters including ones set in the administration area.
Use an overall set of parameters to display all comments for an article or page.
<?php wp_list_comments ($args); ?>
<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
$style comment container tag can be "div", "ol", or "ul", the default value is "ul", if not,Then you need to write it explicitly as follows.
<><?php wp_list_comments (array ("style" =>"div"));?></div>
<<?php wp_list_comments (array ("style" =>"ol"));?></ol>
$type shows what kind of comment,The parameters can be "all", "comment", "trackback", "pingback", "pings". "Pings" includes "trackback" and "pingback".
$reply_text The text value of the reply button.This is rarely used and is not explained. Default:"reply"
$login_text The text value of the login button,This is rarely used and is not explained. Default:"log in to reply"
$callback comment shows the callback function,I.e. the name of the function displaying the comment topic
$end-callback should be the callback function after the loop ends,I have not measured it.Please explore on your own.
$reverse_top_level Boolean, if this parameter is set to true,Display the latest comment first,Subsequent comments are displayed according to the background settings.
$reverse_children Boolean, if this parameter is set to true,The latest comment with child comments is displayed first,Subsequent comments are displayed according to the background settings.
Here is a demo showing the comment in the official default theme twentyeleven,
Specific other parameters, please refer to the above introduction to explore by yourself.
<ol> <?php / * loop through and list the comments. tell wp_list_comments () * to use twentyeleven_comment () to format the comments. * if i 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 function is defined in the theme file "twentyeleven/functions.php". ?> </ol>
- PHP + Mysql no refresh Q&A comment system (source code)
- A way to implement single page comments using Laravel with AngularJS and PHP
- PHP implements comment reply deletion function
- Ways to use comment plugin on ThinkPHP
- PHP captures user comments on Taobao products + pictures + search product list examples
- PHP imitation qq space or circle of friends to post news, comment news, reply to comments, delete news or comments function (on)
- PHP implement article review system