更正wp_get_themes()
函数具有大多数公众无法访问的信息,这要求您使用$theme->get( \'Name\' );
总体安排您可以这样构建一个简单的数组。
// Build new empty Array to store the themes
$themes = array();
// Loads theme data
$all_themes = wp_get_themes();
// Loads theme names into themes array
foreach ($all_themes as $theme) {
$themes[] = $theme->get(\'Name\');
}
// Prints the theme names
print_r( $themes );
将输出
Array (
[0] => Anchor Blank
[1] => Swell - Anchor Hosting
[2] => Swell
)
通过这一步,您可以构建一个包含所有主题数据的数组,如下所示。
// Build new empty Array to store the themes
$themes = array();
// Loads theme data
$all_themes = wp_get_themes();
// Build theme data manually
foreach ($all_themes as $theme) {
$themes{ $theme->stylesheet } = array(
\'Name\' => $theme->get(\'Name\'),
\'Description\' => $theme->get(\'Description\'),
\'Author\' => $theme->get(\'Author\'),
\'AuthorURI\' => $theme->get(\'AuthorURI\'),
\'Version\' => $theme->get(\'Version\'),
\'Template\' => $theme->get(\'Template\'),
\'Status\' => $theme->get(\'Status\'),
\'Tags\' => $theme->get(\'Tags\'),
\'TextDomain\' => $theme->get(\'TextDomain\'),
\'DomainPath\' => $theme->get(\'DomainPath\')
);
}
// Prints the themes
print_r( $themes );
这将输出一个如下所示的数组
Array (
[anchor-blank] => Array
(
[Name] => Anchor Blank
[Description] => Anchor Hosting blank theme
[Author] => Anchor Hosting
[AuthorURI] => https://anchor.host
[Version] => 1.1
[Template] =>
[Status] => publish
[Tags] => Array
(
)
[TextDomain] => anchor-blank
[DomainPath] => /languages/
)
[swell-anchorhost] => Array
(
[Name] => Swell - Anchor Hosting
[Description] => Child theme for Anchor Hosting
[Author] => Anchor Hosting
[AuthorURI] => https://anchor.host
[Version] => 1.1.0
[Template] => swell
[Status] => publish
[Tags] => Array
(
)
[TextDomain] => swell
[DomainPath] => /languages/
)
[swell] => Array
(
[Name] => Swell
[Description] => Swell is a one-column, typography-focused, video Wordpress theme.
[Author] => ThemeTrust.com
[AuthorURI] => http://themetrust.com
[Version] => 1.2.6
[Template] =>
[Status] => publish
[Tags] => Array
(
)
[TextDomain] => swell
[DomainPath] => /languages/
)
)