comments_template() (get comment template)
comments_template() function is used to get the comment template. Generally it can only be used on articles or pages. If it is not an article or page, it will not be displayed.
Usage
comments_template( $file, $separate_comments );
Parameters
$file
(String) (optional) Template file to comment.
Default value: /comments.php (comments.php file in the root directory of the current theme).
$separate_comments
(boolean) (optional) Whether to separate comments based on their type.
Default value: False
Return value
This function has no return value.
Example
Introduce the comments.php file in the root directory of the current theme by default.
<?php comments_template(); ?>
Introduce custom files:
<?php comments_template( '/short-comments.php' ); ?>
Others
This function is located at: wp-includes/comment-template.php
get_search_form() (get search form)
get_search_form() function is used to get Search form, the code of the search form is located in the searchform.php file in the root directory of the current theme.
Usage
get_search_form( $echo );
Parameters
$echo
(Boolean) (optional) If true, the search form will be printed directly, if not true, the code of the search form will be returned.
Default value: True
Return value
(string) If the $echo parameter is False, return the Html code of the search form.
Example
If there is no searchform.php file in the theme root directory, it will default to the form code below:
<form role="search" method="get" action="<?php esc_url( home_url( '/' )); ?>"> <div> <label for="s"><?php _x( 'Search for:', 'label' ); ?></label> <input type="text" value="<?php get_search_query(); ?>" name="s" /> <input type="submit" value="<?php esc_attr_x( 'Search', 'submit button' ); ?>" /> </div> </form>
Others
This function is located at: wp-includes/general-template.php
The above has introduced and explained the PHP functions used to obtain comment templates and search forms in WordPress, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.