2

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?

2 Answers 2

2

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>
5
  • Thanks very much for your code! I only don´t understand why I would list all post instead of the popular ones?
    – Marja
    Commented Feb 6, 2012 at 14:37
  • but it is important, that you write, how you find the popular posts; its not an WP feature; it give different solutions via plugin or tracking tools and the result of this must you use in this example of code
    – bueltge
    Commented Feb 6, 2012 at 15:18
  • ok I understand it now. I just don´t know how to do this ;o) So if anybody can help (me) with this ...
    – Marja
    Commented Feb 11, 2012 at 16:27
  • Ok, so if I understand you correctly. Ican use a plugin like postviews to find the populair posts in a blog, and use those results in your code example?
    – Marja
    Commented Mar 10, 2012 at 10:26
  • Yes, right. Also Google Analytics or any statistic tool
    – bueltge
    Commented Mar 13, 2012 at 20:34
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.