如何列出wordpress mu中所有的模板主题
这需要用到List all themes这个插件,然后还参考了这里
插件实现代码:
<?php
/*
Plugin Name: List-All-Themes
Plugin URI: http://www.wpmudev.org/project/list-all-themes
Description: Creates a list of all themes on a WPMU site
Author: Andrew Billits
Author URI:
Version: 0.0.1
*/
global $name_or_url;
global $begin_wrap;
global $end_wrap;
function list_all_wpmu_themes() {
$themes = get_themes();
$theme_names = array_keys($themes);
natcasesort($theme_names);
echo"<ul>";
foreach ($theme_names as $theme_name) {
if ( $theme_name == $ct->name )
continue;
$title = $themes[$theme_name]['Title'];
$description = $themes[$theme_name]['Description'];
$author = $themes[$theme_name]['Author'];
$screenshot = $themes[$theme_name]['Screenshot'];
?>
<li id="theme-list"><?php echo $title; ?><br />
<img width="180" height="150" src="<?php echo
$themes[$theme_name]['Template Dir']; ?>/<?php echo $screenshot;?>">
<br />by <?php echo $author; ?></li>
<?php }
echo"</ul>"; // end foreach theme_names
}
?>
/*
Plugin Name: List-All-Themes
Plugin URI: http://www.wpmudev.org/project/list-all-themes
Description: Creates a list of all themes on a WPMU site
Author: Andrew Billits
Author URI:
Version: 0.0.1
*/
global $name_or_url;
global $begin_wrap;
global $end_wrap;
function list_all_wpmu_themes() {
$themes = get_themes();
$theme_names = array_keys($themes);
natcasesort($theme_names);
echo"<ul>";
foreach ($theme_names as $theme_name) {
if ( $theme_name == $ct->name )
continue;
$title = $themes[$theme_name]['Title'];
$description = $themes[$theme_name]['Description'];
$author = $themes[$theme_name]['Author'];
$screenshot = $themes[$theme_name]['Screenshot'];
?>
<li id="theme-list"><?php echo $title; ?><br />
<img width="180" height="150" src="<?php echo
$themes[$theme_name]['Template Dir']; ?>/<?php echo $screenshot;?>">
<br />by <?php echo $author; ?></li>
<?php }
echo"</ul>"; // end foreach theme_names
}
?>
将这段保存成php文件,放到mu-plugins目录,或者放在站点模板文件里的functions.php中(我推荐这个)
然后新建一个page模板,
开头加上
/*
Template Name: All themes lists
*/
?>
在合适位置加上
(function_exists(list_all_wpmu_themes))
{list_all_wpmu_themes();} ?>
在css中添加
#content #theme-list{
width: 230px;
float: left;
text-decoration: none;
list-style-type: none;
}
最后新建一个页面,页面模板就取刚刚建的那个。
根据情况,需要修改css中的width值,如果没有侧边栏,而且这个width值合适的话,可以一栏显示三个模板的。
效果见:http://cnlogger.com/themes/
但是这有个问题,会把所有的主题都显示出来了,包括没有激活的,
参照论坛上这个说明,我试了试没有成功,不知道什么原因:(
Popularity: 43% [?]
Tags: mu, wpmuRelated posts



