I have a multisite network on WP 3.3.1. I now need to get all popular posts from across this network (preferably based on the amount of views).
Is this possible, and how do I do that?
simple list all last post about the network, not the popular posts; for popular posts you must use an plugin or track via Google Analytics etc.
<ul class='postlist no-mp'>
<?php
$blogs = $wpdb->get_results(
"SELECT blog_id,path FROM {$wpdb->blogs}
WHERE blog_id != {$wpdb->blogid}
AND site_id = '{$wpdb->siteid}'
AND spam = '0'
AND deleted = '0'
AND archived = '0'
order by blog_id", ARRAY_A
);
if ( 0 < count( $blogs ) ) :
foreach( $blogs as $blog ) :
switch_to_blog( $blog[ 'blog_id' ] );
if ( get_theme_mod( 'show_in_home', 'on' ) !== 'on' ) {
continue;
}
$description = get_bloginfo( 'description' );
$blog_details = get_blog_details( $blog[ 'blog_id' ] );
?>
<li class="no-mp">
<h2 class="no-mp blog_title">
<a href="<?php echo $blog_details->path ?>">
<?php echo $blog_details->blogname; ?>
</a>
</h2>
<div class="blog_description">
<?php echo $description; ?>
</div>
<?php
query_posts( 'showposts=5' );
if ( have_posts() ) :
while( have_posts() ) :
the_post();
?>
<div class="blog_post">
<div class="post_title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div>
<div class="post_excerpt">
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>
<?php endif;
restore_current_blog();
?>
</li>
<?php endforeach;?>
</ul>
You could try using the techniques described here: http://www.artiss.co.uk/2011/07/using-google-analytics-data-to-show-popular-posts
It basically uses the functions provided by the Google Analytics Dashboard plugin to show the most popular post in your theme.