Hi all,
How would I list all blogs/sites and categories without having to connect to the database and use select statements. Blogs/sites would be one drop down box and categories would be another.
My MU site structor is:
Admin - http://name.domain.tld
New user - http://username.name.domain.tld
I have the code working for the most part, but not returning what I need to display.
The first part list all blogs and list them in a drop down with the blog name and site URL. That's great, but I would like to list the display name and site URL. (I can do this by connecting to the database, but thought there might be a better way without opening a connection.). Code below was from an example - can't find the source.
<?php
$current_site = get_current_site()->id;
$blog_list = get_blog_list( 0, 'all' );
$blogs=array();
foreach ($blog_list AS $blog) {
$blogid = $blog['blog_id'];
//if ($blogid != $current_site) {
$name = get_blog_details($blogid)->blogname;
$url = get_blog_details($blogid)->siteurl;
$blogs[] = "$name, $url";
//}
}
sort($blogs);
echo '<h2>Choose your site by Name</h2>'; ?>
<select name="instructor_list" onchange='document.location.href=this.options[this.selectedIndex].value;'>
<option value=""><?php echo attribute_escape(__('--- Select Instructor ---')); ?></option>
<?php foreach ($blogs as $blog) {
list($name, $url) = split(",", $blog);
echo '<option value="' .$url. '"><a href="'.$url.'" title="' .$name. '">' .$name. '</a></option>';
} ?>
</select>
The second part list all categories (or it should). The only thing it list are the categories for the admin blog and not all blogs. Again, I can do this with SQL, but thought there was a way (just like the code below) to list all categories for each user with the exception of a few. The code below was pulled from http://codex.wordpress.org/Function_Reference/get_categories
<?php echo '<h2>Choose your site by Category</h2>'; ?>
<select name="course_list" onchange='document.location.href=this.options[this.selectedIndex].value;'>
<option value=""><?php echo attribute_escape(__('--- Select Course ---')); ?></option>
<?php $categories = get_categories();
foreach ($categories as $cat) {
$option = '<option value="/category/'.$cat->category_nicename.'">';
$option .= $cat->cat_name;
$option .= ' ('.$cat->category_count.')';
$option .= '</option>';
echo $option;
} ?>
</select>