當(dāng)前位置:首頁>WordPress建站>WordPress開發(fā)>WordPress 獲取主題樣式表 style.css 注釋里的信息

WordPress 獲取主題樣式表 style.css 注釋里的信息

我們在 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)行處理。

給TA打賞
共{{data.count}}人
人已打賞
歡迎關(guān)注WordPress大學(xué)公眾號 WPDAXUE
WordPress開發(fā)

檢查 PHP 和 WordPress 的最低版本

2013-12-7 9:49:48

WordPress開發(fā)

WordPress 用戶沒有設(shè)置菜單時顯示提示語

2013-12-16 7:21:01

5 條回復(fù) A文章作者 M管理員
  1. 博主好,請問怎樣獲取主題文件夾名稱.非常感謝

  2. 不錯的介紹

  3. Tmd

    Style.css注釋信息刪除掉,還獲取個P

  4. 不錯,新主題用上了

  5. 收了 這函數(shù)不錯 以前footer都是自己手打主題信息

?
個人中心
購物車
優(yōu)惠劵
今日簽到
有新私信 私信列表
搜索

洛南县| 左贡县| 福泉市| 句容市| 广水市| 河东区| 铅山县| 都安| 富顺县| 伊吾县| 大庆市| 绩溪县| 普兰店市| 永州市| 永城市| 华安县| 化州市| 于都县| 汉阴县| 张家口市| 吉木萨尔县| 巴马| 大同县| 登封市| 隆德县| 华容县| 夏河县| 淮滨县| 游戏| 甘德县| 东方市| 芜湖县| 新闻| 美姑县| 桐城市| 黄平县| 泰和县| 新平| 宜章县| 云梦县| 界首市|