Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Grab array of child themes WordPress

  • SOLVED

Hi,
I need a PHP script which can hunt through the themes directory and return an array of the meta data (ie: child theme name, child theme slug etc) for child themes of a particular parent theme.




Background info ...
This will be incorporated into the admin panel of a parent theme so that users can see a short list of what child themes are available for it on the current installation.

Answers (3)

2011-09-01

John Cotton answers:

Pop this where you need it and you'll get all the info you need:

if(!function_exists('get_allowed_themes')){
require_once( ABSPATH . 'wp-admin/includes/theme.php' );
}
$themes = get_allowed_themes();

foreach( $themes as $theme ) {
if( $theme['Parent Theme'] == 'whatever you want' ) {
// do something
}
}


Ryan Hellyer comments:

Lol, that looks WAYYY too simple :)

I'll go test to confirm it works. But it looks like just hit the nail on the head!

I didn't realise there would be built in functions in core for this.


John Cotton comments:

Hi Ryan

<blockquote>I didn't realise there would be built in functions in core for this.</blockquote>

If you think about it, WordPress has to do pretty much what you want for the themes page on the Appearance tab.

If you have a look in wp-admin/includes/class-wp-themes-list-table.php you can see this function at work. But basically, you're getting an array with all the theme info therein so you can do whatever you need.... :) Neat eh?

John


Ryan Hellyer comments:

Awesome. That did the trick.

I did need to include ms.php too for it to support multisite, but otherwise it worked flawlessly.

2011-09-02

Maor Barazany answers:

2011-09-02

ej_emman answers:

Maybe you can also try this:


<?php
$themes = get_themes();

foreach($themes as $listheme)
{
$listheme['Name'];
// and etc. anything you want display
}
?>