2009-12-03 30 views
3

使用Wordpress主题,需要将信息添加到style.css文件的顶部:从Wordpress中的style.css文件获取主题信息

例如;对于默认主题是这样的:

/* 
Theme Name: WordPress Default 
Theme URI: http://wordpress.org/ 
Description: The default WordPress theme based on the famous <a href="http://binarybonsai.com/kubrick/">Kubrick</a>. 
Version: 1.6 
Author: Michael Heilemann 
Author URI: http://binarybonsai.com/ 
Tags: blue, custom header, fixed width, two columns, widgets 
*/ 

是否有任何wordpress函数以编程方式获取此信息?

回答

3

你可以使用get_theme_data()或这个PHP脚本我赶紧把在一起:

<?php 
$file = file('your file location'); 
$contents = ''; 
foreach($file as $lines => $line){ 
$contents .= $line; 
} 
preg_match('!/\*[^*]*\*+([^/][^*]*\*+)*/!', $contents, $themeinfo); 
echo nl2br($themeinfo[0]); 
?> 
+0

如何在没有Wordpress功能的情况下阅读外部style.css信息? – Gino 2016-04-27 03:08:39

1

注意get_theme_data功能已被废弃在WP 3.4,并与wp_get_theme取代。替换函数不会检索styles.css中的所有相同元素,因为get_theme_data的确具有此功能,具体而言,ThemeURI元素现在返回主题的目录,而不是Theme URL的值。

http://codex.wordpress.org/Function_Reference/wp_get_theme