您好,登錄后才能下訂單哦!
小編給大家分享一下WordPress中如何獲取評論模板和搜索表單,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
comments_template()(獲取評論模板)
comments_template() 函數(shù)用來獲取評論模板,一般只能用在文章或者頁面上,如果不是文章或者頁面將無法顯示。
用法
comments_template( $file, $separate_comments );
參數(shù)
$file
(字符串)(可選)要評論模板文件。
默認(rèn)值:/comments.php(當(dāng)前主題根目錄的 comments.php 文件)。
$separate_comments
(布爾)(可選)是否根據(jù)評論的類型區(qū)分評論。
默認(rèn)值:False
返回值
此函數(shù)無返回值。
例子
默認(rèn)引入當(dāng)前主題根目錄的 comments.php 文件。
<?php comments_template(); ?>
引入自定義文件:
<?php comments_template( '/short-comments.php' ); ?>
其它
此函數(shù)位于:wp-includes/comment-template.php
get_search_form()(獲取搜索表單)
get_search_form() 函數(shù)用來獲取搜索表單,搜索表單的代碼位于當(dāng)前主題根目錄的 searchform.php 文件。
用法
get_search_form( $echo );
參數(shù)
$echo
(布爾)(可選)如果為真則直接打印搜索表單,如果不為真則返回搜索表單的代碼。
默認(rèn)值:True
返回值
(string)如果 $echo 參數(shù)為 False,則返回搜索表單的 Html 代碼。
例子
如果主題根目錄沒有 searchform.php 文件,則默認(rèn)為下邊的表單代碼:
<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>
看完了這篇文章,相信你對“WordPress中如何獲取評論模板和搜索表單”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。