在我们制作一款WordPress主题时,为了方便推送最新版主题给用户,一般会加入主题更新功能。WordPress主题更新原理是,PHP访问作者提供的更新校验文件,获取校验文件中的版本信息,然后通过用户端获取主题版本,两者比较即可得出是否有最新主题需要更新。下面介绍获取WordPress在3.4版本后提供的获取主题信息函数wp_get_themes();

arg1:内容为查询的主题名,可选。
默认值:null
arg2:主题根要查看的绝对路径。可选。如果没有指定,get_raw_theme_root()用于计算主题根为样式表提供(或当前主题)。
默认值:null
Version:获取主题版本(位于主题目录下的style.CSS文件中)
Name:主题的名字
ThemeURI:主题的URL信息
Description:主题的描述信息
Author:作者名字
AuthorURI:作者的主页地址
Template:模板……未知内容
Status:状态……未知内容
Tags:标签
TextDomAIn:未知内容
…….
不常用就不说了
返回数组型主题对象
该函数位于wp-includes/theme.php文件中,内容如下:
function wp_get_theme( $stylesheet = null, $theme_root = null ) {
global $wp_theme_directories;if ( empty( $stylesheet ) )
$stylesheet = get_stylesheet();if ( empty( $theme_root ) ) {
$theme_root = get_raw_theme_root( $stylesheet );
if ( false === $theme_root )
$theme_root = WP_CONTENT_DIR . '/themes';
elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) )
$theme_root = WP_CONTENT_DIR . $theme_root;
}return new WP_Theme( $stylesheet, $theme_root );
}查询某个主题信息:wp_get_theme(‘主题名’);
在返回的数据中取出常用字段即可得到你想要数据。
如:
$theme_data = wp_get_theme('daimadog'); echo $theme_data['Version'];
安装KB5014697补丁以后开启热点无法上网怎么办?
Windows 11 的最新星期二补丁KB5014697更...(627 )人阅读时间:2025-11-25
Win11本地安全策略在哪里?Win11添加IP 安全策略的
IP安全策略是一个给予通讯分析的策略,当我们配置好IP安全...(948 )人阅读时间:2025-11-25
Win11字体显示不全如何解决?Win11字体显示不全解决方
Win11系统是当前最好用的系统之一,在给用户带来全新界面...(752 )人阅读时间:2025-11-25
Win11怎么创建虚拟磁盘?Win11创建虚拟磁盘的方法
虚拟磁盘就是用内存中虚拟出一个或者多个磁盘的技术。和虚拟内...(607 )人阅读时间:2025-11-25