5ucms论坛

标题: wp_get_theme()函数 获取主题的相关信息 [打印本页]

作者: admin    时间: 2021-6-3 16:20
标题: wp_get_theme()函数 获取主题的相关信息
wp_get_theme()函数主要作用是用来获得WordPress主题的相关信息。
语法

  1. <?php wp_get_theme($stylesheet, $theme_root) ?>
复制代码

参数

参数1:内容为查询的主题名,可选。默认值:null

参数2:主题根要查看的绝对路径。可选。如果没有指定,get_raw_theme_root()用于计算主题根为样式表提供(或当前主题)。默认值:null

实例

  1. <?php
  2. $theme = wp_get_theme();
  3. echo $theme->get( 'Name' ); //主题名
  4. echo $theme->get( ThemeURI' ); //主题 URL
  5. echo $theme->get( Description' ); //主题描述
  6. echo $theme->get( Author' ); //作者名
  7. ?>
复制代码

wp_get_theme()函数详细参数:
Name:主题名
ThemeURI:主题 URL
Description:主题描述
Author:作者名
AuthorURI:作者 URL
Version:主题版本号
Template:父主题的文件夹名称,子主题中使用
Status:主题状态,如果发布的话
Tags:标签
TextDomain:主题中用于翻译目的的文本域
DomainPath:主题翻译文件路径

当然啦,wp_get_theme()函数还可以指定主题名来获取指定主题的其它信息,如下:

  1. <?php
  2. $theme = wp_get_theme( 'Viti' );
  3. if ( $theme->exists() )
  4. echo $theme;
  5. ?>
复制代码






欢迎光临 5ucms论坛 (http://bbs.5ucms.com/) Powered by Discuz! X3.2