自定义WordPress字符串截取函数
一般情况下,当我们制作WordPress列表页的时候,会需要截取一部分正文内容作为列表的文章摘要,当然,WordPress默认的是有一个字符串截取函数,那就是w…
目录
最近在研究WordPress的站群,也就是多站点功能,想着使用WordPress的站群功能制作一个WordPress自助建站的一个Saas平台,在思考与规划中我需要把站群中的所有主题以列表的形式展现的前台,从而方便用户查看和选择主题,那么这个时候就需要获取当前站群平台程序中的所有主题信息,于是找到了函数wp_get_themes();
根据参数返回WP_Theme对象的数组。
<?php
$all_themes = wp_get_themes();
print_r($all_themes);
?>
$args
(array) (可选) 用来查询的参数
默认值: array()
function wp_get_themes( $args = array() ) {
global $wp_theme_directories;
$defaults = array(
'errors' => false,
'allowed' => null,
'blog_id' => 0,
);
$args = wp_parse_args( $args, $defaults );
$theme_directories = search_theme_directories();
if ( is_array( $wp_theme_directories ) && count( $wp_theme_directories ) > 1 ) {
// Make sure the current theme wins out, in case search_theme_directories() picks the wrong
// one in the case of a conflict. (Normally, last registered theme root wins.)
$current_theme = get_stylesheet();
if ( isset( $theme_directories[ $current_theme ] ) ) {
$root_of_current_theme = get_raw_theme_root( $current_theme );
if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) ) {
$root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme;
}
$theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme;
}
}
if ( empty( $theme_directories ) ) {
return array();
}
if ( is_multisite() && null !== $args['allowed'] ) {
$allowed = $args['allowed'];
if ( 'network' === $allowed ) {
$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_network() );
} elseif ( 'site' === $allowed ) {
$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_site( $args['blog_id'] ) );
} elseif ( $allowed ) {
$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) );
} else {
$theme_directories = array_diff_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) );
}
}
$themes = array();
static $_themes = array();
foreach ( $theme_directories as $theme => $theme_root ) {
if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) {
$themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ];
} else {
$themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ] = new WP_Theme( $theme, $theme_root['theme_root'] );
}
}
if ( null !== $args['errors'] ) {
foreach ( $themes as $theme => $wp_theme ) {
if ( $wp_theme->errors() != $args['errors'] ) {
unset( $themes[ $theme ] );
}
}
}
return $themes;
}
WordPress日记主要承接WordPress主题定制开发、PSD转WordPress、WordPress仿站以及以WordPress为管理后端的小程序、APP,我们一直秉持“做一个项目,交一个朋友”的理念,希望您是我们下一个朋友。如果您有WordPress主题开发需求,可随时联系QQ:919985494 微信:18539976310