我們在 Style.css 中都會填入自己的主題信息,例如名稱或版本號等,以便 WordPress 展現(xiàn)給用戶。以下是WP官方 2014 主題的注釋:
/*
Theme Name: Twenty Fourteen
Theme URI: https://wordpress.org/themes/twentyfourteen
Author: the WordPress team
Author URI: https://wordpress.org/
Description: In 2014, our default theme lets you create a responsive magazine website with a sleek, modern design. Feature your favorite homepage content in either a grid or a slider. Use the three widget areas to customize your website, and change your content's layout with a full-width page template and a contributor page to show off your authors. Creating a magazine website with WordPress has never been easier.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: black, green, white, light, dark, two-columns, three-columns, left-sidebar, right-sidebar, fixed-layout, responsive-layout, custom-background, custom-header, custom-menu, editor-style, featured-images, flexible-header, full-width-template, microformats, post-formats, rtl-language-support, sticky-post, theme-options, translation-ready, accessibility-ready
Text Domain: twentyfourteen
This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/
從中可以看到主題名稱、主題鏈接、作者、作者鏈接、版本等等信息。在 WordPress 3.4 以上的版本中,我們可以直接使用 wp_get_theme() 這個函數(shù)來獲取這些信息。以下是一些簡單的例子:
獲取當(dāng)前主題名字:
<?php
echo wp_get_theme();
?>
獲取其它主題名字:
<?php
$my_theme = wp_get_theme( 'twentyten' );
if ( $my_theme->exists() )
echo $my_theme;
?>
獲取當(dāng)前主題版本號:
<?php
$my_theme = wp_get_theme();
echo $my_theme->get( 'Name' ) . " is version " . $my_theme->get( 'Version' );
?>
顯示當(dāng)前主題作者的鏈接:
<?php
$my_theme = wp_get_theme();
echo $my_theme->get( 'AuthorURI' );
?>
更多介紹,請閱讀WP官方的 wp_get_theme() 文檔
聲明:本站所有文章,如無特殊說明或標(biāo)注,均為本站原創(chuàng)發(fā)布。任何個人或組織,在未征得本站同意時,禁止復(fù)制、盜用、采集、發(fā)布本站內(nèi)容到任何網(wǎng)站、書籍等各類媒體平臺。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。






博主好,請問怎樣獲取主題文件夾名稱.非常感謝
不錯的介紹
Style.css注釋信息刪除掉,還獲取個P
不錯,新主題用上了
收了 這函數(shù)不錯 以前footer都是自己手打主題信息