php – 无法让WordPress显示Multisite中的所有类别
发布时间:2020-12-13 17:25:45 所属栏目:PHP教程 来源:网络整理
导读:我正在使用WordPress Multisite,我试图在一个页面上显示每个站点中的所有类别.当我在我的管理员帐户上时,以下代码有效.但是,当我切换到任何其他帐户时,不会显示任何类别. $t=get_current_blog_id();foreach(function_that_gets_blogs() as $k=$blog){ switch
我正在使用WordPress Multisite,我试图在一个页面上显示每个站点中的所有类别.当我在我的管理员帐户上时,以下代码有效.但是,当我切换到任何其他帐户时,不会显示任何类别.
$t=get_current_blog_id(); foreach(function_that_gets_blogs() as $k=>$blog){ switch_to_blog($blog['blog_id']); print_r(get_categories(array('hide_empty'=>true))); // prints "array()" foreach(get_categories(array('hide_empty'=>true)) as $cat){ ... } } switch_to_blog($t); 为什么不显示类别? 解决方法
像
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 自3.0版以来,函数 // 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> ',$name ); } } // return to the current site switch_to_blog( $current->id ); 就那么简单… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 如何解决错误QXcbConnection:使用PHP的phantomJs使用exec函
- PHP setcookie指定domain参数后,在IE下设置cookie失效的解决
- PHP数据流应用的一个简单实例
- ubuntu安装配置JDK
- PHP mailparse.so错误 – 未定义的符号mbfl_convert_filter
- php使用curl获取https请求的方法
- 使用symfony2和php在生产环境中使用doctrine2迁移是否安全
- php合并js请求的例子
- php – WP – 高级自定义字段:acf_add_options_page()不存
- php – google analytics api查询一个特定的url