Get the App
SLTechnology News&Howtos  ›  Development  › 

How to get comment template and search form in WordPress

Shulou Source: shulou.com Published: 2022-06-03 19:33:49 11月12日 Update

Xiaobian to share with you how to get comment templates and search forms in WordPress, I hope you have something to gain after reading this article, let's discuss it together!

comments_template()

comments_template() function is used to get comments template, generally can only be used in articles or pages, if not articles or pages will not be displayed.

usage

comments_template( $file, $separate_comments );

parameters

$file

(String)(Optional) To comment on the template file.

Default: /comments.php (comments.php file in the root directory of the current topic).

$separate_comments

(Boolean)(Optional) Whether to differentiate reviews based on their type.

Default: False

return value

This function has no return value.

example

By default, the comments.php file is introduced into the root directory of the current topic.

Introducing custom files:

other

This function is located at: wp-includes/comment-template.php

get_search_form()

The get_search_form() function is used to get the search form whose code is located in the searchform.php file in the root directory of the current topic.

usage

get_search_form( $echo );

parameters

$echo

(Boolean)(Optional) If true prints the search form directly, if not true returns the search form code.

Default: True

return value

(string) If the $echo parameter is False, returns the Html code of the search form.

example

If there is no searchform.php file in the topic root directory, the default is the following form code:

Tags: Forms searches comments files templates themes codes functions root directories parameters examples Boolean articles articles pages characters strings over more knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Linux NVidia OPPO Reno Microsoft