The MU forums have moved to WordPress.org

WP-PostViews and Global Tags (3 posts)

  1. xenon2050
    Member
    Posted 13 years ago #

    So I'm using the Global Tags to import all the post into the main blog, but I've noticed that the WP-PostViews page views custom field doesn't transfer in. Is there a way to make this work right?

    I've seen other WPMU sites have a "views" listing on the main page and I'm shooting for similar functionality.

  2. xenon2050
    Member
    Posted 13 years ago #

    Figure I'll put a little bump here...

  3. hermeslin
    Member
    Posted 13 years ago #

    Dear xenon2050:
    I have this problem too, so I resolve this problem using the function that I write, try this :)

    this function can shwo sitewide postviews, but you should give it the right parameters

    function the_sitewide_postviews($blogID, $postID)
    {
        $postviews = 0;
    
        if (0 < (int) $blogID && 0 < (int) $postID)
        {
            switch_to_blog($blogID);
            $postviews = intval(get_post_meta($postID, 'views', true));
            restore_current_blog();
        }
    
        return $postviews;
    }

    but, how do I get the right blogID and postID from the main blog?
    on the main blog's front page, I assumed that you using the loop statement to get the post like this:

    global $post;
    while (have_posts()) : the_post();
    
        echo 'the title is ' . $post->post_title;
        echo 'the content is ' . $post->post_content;
    
    endwhile;

    now, we can add some code in this loop statement:

    global $post;
    while (have_posts()) : the_post();
    
        list($blogID, $postID) = explode('.', $post->guid);
    
        echo 'the title is ' . $post->post_title;
        echo 'the content is ' . $post->post_content;
        echo 'the sitewide postwies is ' . the_sitewide_postviews($blogID, $postID);
    
    endwhile;

    hope this can help you :)

About this Topic

  • Started 13 years ago by xenon2050
  • Latest reply from hermeslin