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

WBOY
Release: 2016-07-29 09:08:41
Original
1010 people have browsed it

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 );
Copy after login

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.

<&#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)
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 );
Copy after login

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="<&#63;php esc_url( home_url( '/' )); &#63;>">
  <div>
    <label for="s"><&#63;php _x( 'Search for:', 'label' ); &#63;></label>
    <input type="text" value="<&#63;php get_search_query(); &#63;>" name="s" />
    <input type="submit" 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

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.

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template