就像b__说你应该检查:
- 您在哪里使用此代码?(functions.php,插件)
- 您应该逐个禁用插件,以检查是否有一些干扰
- 在最后一种情况下改变主题
我做过像你这样的事情,这是代码,以防你想试试:
// Current Site
$current = get_current_site();
// All Sites
$blogs = get_blog_list( 0, 'all' );
foreach ( $blogs as $blog ) {
// switch to the blog
switch_to_blog( $blog['blog_id'] );
// get_categories args
$args = array(
'hide_empty' => true
);
$categories = get_categories( $args );
foreach ( $categories as $category ) {
$link = get_category_link( $category->term_id );
$name = $category->name;
printf( '<a href="%s" title="%s">%s</a> ', $link, $name, $name );
}
}
// return to the current site
switch_to_blog( $current->id );
更新 2014/06/01
该功能get_blog_list();
自 3.0 版以来已弃用,您应该在其中更改该功能wp_get_sites();
// Current Site
$current = get_current_site();
// All Sites
$blogs = wp_get_sites();
foreach ( $blogs as $blog ) {
// switch to the blog
switch_to_blog( $blog['blog_id'] );
// get_categories args
$args = array(
'hide_empty' => true
);
$categories = get_categories( $args );
foreach ( $categories as $category ) {
$link = get_category_link( $category->term_id );
$name = $category->name;
printf( '<a href="%s" title="%s">%s</a> ', $link, $name, $name );
}
}
// return to the current site
switch_to_blog( $current->id );
就那么简单...