is_page_template 判断是否使用了指定的page模板

WordPress 主题可以使用 is_page_template 判断当前 page 使用的模板文件。此函数在实际中的用途,尚未明了……

如果一个模板文件存在,比如 about.php 。那么在 about.php 中 is_page_template('about.php') 必为 true。如果 about.php 不存在,无论在那里判断 is_page_template('about.php') 也是 false ……

也想出现在这里?联系我们
创客主机

能想到的,在一些公共的文件中,比如:header.php、fotter.php 中,有一些用处。

  1. if ( is_page_template( 'about.php' ) ) {
  2.     // about.php is used
  3. } else {
  4.     // about.php is not used
  5. }

如果模板在目录中,使用函数时,也要带上目录。比如 about.php 在目录 tpl 中,则正确的写法是:is_page_template( 'tpl/about.php' )

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!