Home > Backend Development > PHP Tutorial > Explain the PHP functions used to obtain comment templates and search forms in WordPress, wordpressphp_PHP tutorial

Explain the PHP functions used to obtain comment templates and search forms in WordPress, wordpressphp_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-12 09:02:18
Original
908 people have browsed it

Explain the PHP functions used to obtain comment templates and search forms in WordPress, wordpressphp

comments_template() (get comment template)

The comments_template() function is used to obtain 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 );
Copy after login

Parameters

$file

(string) (optional) Template file to comment on.

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

$separate_comments

(boolean) (optional) Whether to differentiate comments based on their type.

Default value: False

Return value

This function has no return value.

Example

The comments.php file in the root directory of the current theme is imported by default.

<&#63;php comments_template(); &#63;>
Copy after login

Introduce custom files:

<&#63;php comments_template( '/short-comments.php' ); &#63;>
Copy after login

Others

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


get_search_form() (get search form)
The get_search_form() function is used to obtain the 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 );
Copy after login

Parameters

$echo

(Boolean) (optional) If true, print the search form directly, if not, return the code of the search form.

Default value: 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 theme root directory, the form code below will default to:

<form role="search" method="get" id="searchform" class="searchform" action="<&#63;php esc_url( home_url( '/' )); &#63;>">
  <div>
    <label class="screen-reader-text" for="s"><&#63;php _x( 'Search for:', 'label' ); &#63;></label>
    <input type="text" value="<&#63;php get_search_query(); &#63;>" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="<&#63;php esc_attr_x( 'Search', 'submit button' ); &#63;>" />
  </div>
</form>
Copy after login

Others

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

Articles you may be interested in:

  • Getting the header template and bottom template in WordPress theme writing
  • How to introduce template files in WordPress theme production

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1085878.htmlTechArticle explains the PHP functions used to obtain comment templates and search forms in WordPress, wordpressphp comments_template() (get comment template) The comments_template() function is used to get the comment template,...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Pemasangan WordPress berasaskan Nginx gagal?
From 1970-01-01 08:00:00
0
0
0
Pinnen Sie die WordPress-Version auf wp-cli
From 1970-01-01 08:00:00
0
0
0
Ralat ini berlaku selepas memasang wordpress
From 1970-01-01 08:00:00
0
0
0
Nginx-based WordPress installation fails?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template