我发现这个功能非常酷,可以列出多站点网络安装上的所有博客。
因为原来multisite list blogs function 已折旧:/
所以我在下面使用这个函数,它很好,因为它很灵活。
但我似乎唯一无法解决的问题是如何对get\\u results查询重新排序。请任何人帮助我了解如何按博客id而不是当前输出的字母顺序重新排序此查询。
function projects_menu($link_self = true)
{
global $wpdb;
echo \'<ul class="nav nav-list">\';
$blogs = $wpdb->get_results("
SELECT blog_id
FROM {$wpdb->blogs}
WHERE site_id = \'{$wpdb->siteid}\'
AND spam = \'0\'
AND deleted = \'0\'
AND archived = \'0\'
AND blog_id != 1
");
$sites = array();
foreach ($blogs as $blog) {
$sites[$blog->blog_id] = get_blog_option($blog->blog_id, \'blogname\');
}
natsort($sites);
foreach ($sites as $blog_id => $blog_title) {
projects_menu_entry($blog_id, $blog_title, $link_self);
}
echo \'</ul>\';
}
此函数的来源https://gist.github.com/davejamesmiller/1966341
提前谢谢。
看到了吧,这应该行得通,但不行。。。
$blogs = $wpdb->get_results("
SELECT blog_id
FROM {$wpdb->blogs}
WHERE site_id = \'{$wpdb->siteid}\'
AND spam = \'0\'
AND deleted = \'0\'
AND archived = \'0\'
AND blog_id != 1
ORDER BY blog_id
");
<小时/>
// EVENTS SITEMAP
function projects_menu_entry($id, $title, $link_self)
{
global $blog_id;
if ($link_self || $id != $blog_id) {
if ($id == $blog_id) {
echo \'<li class="active">\';
} else {
echo \'<li>\';
}
$url = get_home_url($id);
if (substr($url, -1) != \'/\') {
// Note: I added a "/" to the end of the URL because WordPress
// wasn\'t doing that automatically in v3.0.4. YMMV.
$url .= \'/\';
}
echo \'<a class="notranslate" href="\' . $url . \'"><i class="icon-folder-close"></i> \' . $title . \'</a>\';
echo \'</li>\';
}
}
function projects_menu($link_self = true)
{
global $wpdb;
echo \'<ul class="nav nav-list">\';
echo \'<li class="nav-header">Admin sitemap</li>\';
$query = "
SELECT blog_id
FROM $wpdb->blogs
WHERE site_id = %d
AND public = \'1\'
AND archived = \'0\'
AND mature = \'0\'
AND spam = \'0\'
AND deleted = \'0\'
AND blog_id != \'1\'
ORDER BY blog_id ASC";
$blogs = $wpdb->get_col( $wpdb->prepare( $query, $wpdb->siteid ) );
$sites = array();
foreach ($blogs as $blog) {
$sites[$blog->blog_id] = get_blog_option($blog->blog_id, \'blogname\');
}
foreach ($sites as $blog_id => $blog_title) {
projects_menu_entry($blog_id, $blog_title, $link_self);
}
projects_menu_entry(1, \'Home\', $link_self);
echo \'</ul>\';
}
请参见上面我的函数“尝试”列出我网站上的所有博客,并显示当前通过活动类查看的博客。
但是上面的代码只返回一个站点。和主页链接。