首先在你使用主题的funtions.php里面添加下代码:
//根据时间显示最新的分类文章内容,每个站点显示一篇内容 //$blog_id 子站点ID //$catid 分类ID wp_reset_query(); switch_to_blog($blog_id); global $post;?> $my_query2 = new WP_Query('showposts=1&order=desc&orderby=date&cat='.$catid); while ($my_query2->have_posts()) : $my_query2->the_post();
接下来获取分类ID号,使用方法是
global $wpdb; $most_viewed_cat = $wpdb->get_results("SELECT * from $wpdb->blogs"); foreach ($most_viewed_cat as $keyc => $vc) { if($vc->blog_id !=1) //排除主站点ID { $id_cat[$keyc] = $vc->blog_id; } } $newid = array_flip($id_cat); $new_array_cat = array_rand($newid,10); $n_post = array_filter($new_array_cat); foreach ($n_post as $ksc => $volsc) { $most_cat = $wpdb->get_results("SELECT * from wp_".$volsc."_terms where name = '最新博文'"); foreach ($most_cat as $ks => $vs) { get_cat_blogposts_wpmu($volsc,$vs->term_id); //方法调用 } }