讲解WordPress中用于获取评论模板和搜索表单的PHP函数

yipeiwu_com6年前PHP代码库

comments_template()(获取评论模板)

comments_template() 函数用来获取评论模板,一般只能用在文章或者页面上,如果不是文章或者页面将无法显示。
用法

comments_template( $file, $separate_comments );

参数

$file

(字符串)(可选)要评论模板文件。

默认值:/comments.php(当前主题根目录的 comments.php 文件)。

$separate_comments

(布尔)(可选)是否根据评论的类型区分评论。

默认值:False

返回值

此函数无返回值。

例子

默认引入当前主题根目录的 comments.php 文件。

<?php comments_template(); ?>

引入自定义文件:

<?php comments_template( '/short-comments.php' ); ?>

其它

此函数位于:wp-includes/comment-template.php


get_search_form()(获取搜索表单)
get_search_form() 函数用来获取搜索表单,搜索表单的代码位于当前主题根目录的 searchform.php 文件。

用法

get_search_form( $echo );

参数

$echo

(布尔)(可选)如果为真则直接打印搜索表单,如果不为真则返回搜索表单的代码。

默认值:True

返回值

(string)如果 $echo 参数为 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>

其它

此函数位于:wp-includes/general-template.php

相关文章

PHP编程获取各个时间段具体时间的方法

本文实例讲述了PHP编程获取各个时间段具体时间的方法。分享给大家供大家参考,具体如下: <?php echo "今天:".date("Y-m-d")."<br&g...

PHP5 字符串处理函数大全

addcslashes — 为字符串里面的部分字符添加反斜线转义字符 addslashes — 用指定的方式对字符串里面的字符进行转义 bin2hex — 将二进制数据转换成十六进制表示...

AJAX的跨域访问-两种有效的解决方法介绍

新的W3C策略实现了HTTP跨域访问,还亏我找了很久的资料解决这个问题:只需要在servlet中返回的头部信息中添加Access-Control-Allow-Origin这个既可。比如我...

php以fastCGI的方式运行时文件系统权限问题及解决方法

php以fastCGI的方式运行时文件系统权限问题及解决方法

今天准备将一个php demo放在IIS下运行,网站在IIS下的配置是这样的: 应用程序池是集成模式下的.net framework 2.0(2.0或4.0没什么关系,因为php以fas...

浅谈php提交form表单

处理GET请求 实现的功能是输入姓名后页面显示“Hello XXX” 创建html文件hello.html: <!DOCTYPE html> <html>...