admin管理员组文章数量:1327962
I am using this function
that gives me a shortcode
I can paste anywhere on the site. It lists all blogs in the multisite network
a user has, but I would like to hide the main site from the list.
Can someone help to adjust the snippet?
-Extra question. - is it possible to show blogs website preview like Facebook?
function show_blog_list() {
$user_id = get_current_user_id();
if ($user_id == 0) {
echo 'You are not logged in.';
} else {
echo '<h2>Here is your blog list</h2>';
$user_blogs = get_blogs_of_user( $user_id );
foreach ($user_blogs AS $user_blog) {
echo '<li><a href="'.$user_blog->siteurl.'">'.$user_blog->blogname.'</a></li>';
}
echo '</ul>';
}
}
add_shortcode( 'bloglist', 'show_blog_list' );
I am using this function
that gives me a shortcode
I can paste anywhere on the site. It lists all blogs in the multisite network
a user has, but I would like to hide the main site from the list.
Can someone help to adjust the snippet?
-Extra question. - is it possible to show blogs website preview like Facebook?
function show_blog_list() {
$user_id = get_current_user_id();
if ($user_id == 0) {
echo 'You are not logged in.';
} else {
echo '<h2>Here is your blog list</h2>';
$user_blogs = get_blogs_of_user( $user_id );
foreach ($user_blogs AS $user_blog) {
echo '<li><a href="'.$user_blog->siteurl.'">'.$user_blog->blogname.'</a></li>';
}
echo '</ul>';
}
}
add_shortcode( 'bloglist', 'show_blog_list' );
Share
Improve this question
edited Jul 30, 2020 at 12:14
Sanfe
asked Jul 30, 2020 at 10:53
SanfeSanfe
11 bronze badge
1 Answer
Reset to default 1I've never used it, but it looks like get_main_site_id
is what you want to figure that out, so therefore your code might look like:
$mainSiteId = get_main_site_id();
foreach ($user_blogs AS $user_blog) {
if ($userblog->site_id != $mainSiteId) {
echo '<li><a href="'.$user_blog->siteurl.'">'.$user_blog->blogname.'</a></li>';
}
}
本文标签: phpList all blogsbut exclude the main site
版权声明:本文标题:php - List all blogs, but exclude the main site 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742221149a2435450.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论