講解WordPress中用于獲取評論模板和搜索表單的PHP函數(shù)
comments_template()(獲取評論模板)
comments_template() 函數(shù)用來獲取評論模板,一般只能用在文章或者頁面上,如果不是文章或者頁面將無法顯示。
用法
comments_template( $file, $separate_comments );
參數(shù)
$file
(字符串)(可選)要評論模板文件。
默認值:/comments.php(當前主題根目錄的 comments.php 文件)。
$separate_comments
(布爾)(可選)是否根據(jù)評論的類型區(qū)分評論。
默認值:False
返回值
此函數(shù)無返回值。
例子
默認引入當前主題根目錄的 comments.php 文件。
<?php comments_template(); ?>
引入自定義文件:
<?php comments_template( '/short-comments.php' ); ?>
其它
此函數(shù)位于:wp-includes/comment-template.php
get_search_form()(獲取搜索表單)
get_search_form() 函數(shù)用來獲取搜索表單,搜索表單的代碼位于當前主題根目錄的 searchform.php 文件。
用法
get_search_form( $echo );
參數(shù)
$echo
(布爾)(可選)如果為真則直接打印搜索表單,如果不為真則返回搜索表單的代碼。
默認值:True
返回值
(string)如果 $echo 參數(shù)為 False,則返回搜索表單的 Html 代碼。
例子
如果主題根目錄沒有 searchform.php 文件,則默認為下邊的表單代碼:
<form role="search" method="get" id="searchform" class="searchform" action="<?php esc_url( home_url( '/' )); ?>"> <div> <label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label> <input type="text" value="<?php get_search_query(); ?>" name="s" id="s" /> <input type="submit" id="searchsubmit" value="<?php esc_attr_x( 'Search', 'submit button' ); ?>" /> </div> </form>
其它
此函數(shù)位于:wp-includes/general-template.php
相關(guān)文章
用mysql_fetch_array()獲取當前行數(shù)據(jù)的方法詳解
本篇文章是對使用mysql_fetch_array()獲取當前行數(shù)據(jù)的方法進行了詳細的分析介紹,需要的朋友參考下2013-06-06PHP實現(xiàn)的常規(guī)正則驗證helper公共類完整實例
這篇文章主要介紹了PHP實現(xiàn)的常規(guī)正則驗證helper公共類,結(jié)合完整實例形式分析了php針對常規(guī)的電話、手機、郵箱、賬號等進行正則驗證的操作技巧,需要的朋友可以參考下2017-04-04