Function Reference/get page templates

来自WordPress中文文档
跳转至: 导航搜索

Description

This function returns the available page templates in the currently active theme. It searches all the current theme's template files for the commented Template Name: name of template. See also get_current_theme() and the wp_get_theme()->get_page_templates() method of the WP_Theme class.

Usage

%%% <?php $templates = get_page_templates(); ?> %%%

Parameters

None.

Return Value

(array) 
Where key is the filename and value is the name of the template.

Examples

Output a list of available templates

The following code snippet loops through the available page templates and outputs their template names and the filenames.

<?php 
   $templates = get_page_templates();
   foreach ( $templates as $template_name => $template_filename ) {
       echo "$template_name ($template_filename)<br />";
   }
?>
<?php print_r(get_page_templates());?>
Array
(
    [Sidebar] => sidebar.php
    [Category] => category.php
    [Page] => page.php
    [Home] => home.php
    [Single] => single.php
    [Comments Popup] => comments-popup.php
    [Footer] => footer.php
    [Header] => header.php
    [Index] => index.php
    [Contact] => contact.php
    [Home-Intro] => home-intro.php
    [Sidebar Left] => sidebar-left.php
    [Sidebar Right] => sidebar-right.php
    [TOC Home] => page-client-toc.php
    [Search Form] => searchform.php
    [Main-Navbar] => main-navbar.php
    [Bookmarks] => page-bookmarks.php
)

Source File

get_page_templates() is located in onlyincludecodewp-admin/includes/theme.php/code/onlyinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Template Description

Link to the source code on http://core.trac.wordpress.org/browser/.

Parameters

  1. filename
  2. (option) path to codetag/code (version) or codetrunk/code. This option is only used for a new function.br /Default: codetrunk/code -- trunk is the latest bleeding edge development version of WordPress.

Usage

Link to the stable version: pre检查到模板循环:模板:Trac/pre

Link to trunk: pre检查到模板循环:模板:Trac/pre

/div

wordpress.org.cn.

Related

get_stylesheet_directory, get_current_theme

includeonlydiv style=clear:both; background-color:#F7F7F7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;See also index of Function Reference and index of Template Tags./div/includeonlynoinclude

Description

This Template is used by Codex:Template Messages.

Usage

pre 检查到模板循环:模板:Message /pre

Result

检查到模板循环:模板:Message

/noinclude