Home>

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.

description

As mentioned above,Is a function that calls the comment template.

use

 <php comments_template ($file, $separate_comments);?>

among them

$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

Use case

 <?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.

description

displays all comments for a post or page based on a variety of parameters including ones set in the administration area.

My understanding:

Use an overall set of parameters to display all comments for an article or page.

usage

<?php
   wp_list_comments ($args);
?>

Parameter use

<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>

or

<<?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".

Default:"all"

$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.

Examples

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
  • Previous PHP to implement the shopping cart function (below)
  • Next Comparison of three common storage engine features for MySQL database
  • Trends