此方法将为您提供活动博客的选择菜单。
function list_all_blogs() {
global $wpdb;
$query = "SELECT blog_id FROM " . $wpdb->base_prefix . "blogs WHERE spam != \'1\' AND archived != \'1\' AND deleted != \'1\' AND public = \'1\' AND blog_id != \'1\' ORDER BY path";
$blogs = $wpdb->get_results($query);
echo \'<select id="blog-select">\';
foreach($blogs as $blog) {
$blog_details = get_blog_details($blog->blog_id);
echo \'<option value="\'. $blog_details->siteurl .\'">\' . $blog_details->blogname .\'</option>\';
}
echo \'</select>\';
}
//call the method
list_all_blogs();
您需要创建一个脚本来导航到菜单选择上的页面。类似这样:
<script>
$(document).ready(function($){
$(\'#blog-select\').change(function(){
window.location.replace( $(this).val() );
});
});
</script>
当然还有其他方法可以做到这一点,也许还有更有效的方法,但我希望这能有所帮助。