The MU forums have moved to WordPress.org

WPMU Aggregator with a template (10 posts)

  1. TNLNYC
    Member
    Posted 17 years ago #

    I've created a theme that allows to aggregate all the blogs on a WPMU install and thought someone else might benefit from it...

    Instructions:
    1. Create a page called page-aggregator.php in your theme.
    2. Change the following lines in the code:

    define ('Host','localhost');
    define ('User','Your DB Username');
    define ('Password','Your DB Password');
    define ('BlogDB','Your DB');

    3. There is no step 3. You expected something more difficult?

    and here's the code to put in your template....

    <?php
    /*
    Template Name: Aggregator
    */
    get_header();?>
    <div id="content">
    <div id="content-main">
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php
    define ('Host','localhost');
    define ('User','Your DB Username');
    define ('Password','Your DB Password');
    define ('BlogDB','Your DB');
    function thisblogname($thisblognumber)
    {
    $Blogname_Request = "SELECT * FROM
    wp_".$thisblognumber."_options WHERE option_name LIKE CONVERT( _utf8 'blogname' USING latin1 ) COLLATE latin1_swedish_ci LIMIT 0 , 1";
    $BlogDB_Link = mysql_connect (Host,User,Password);
    $myblogname = mysql_db_query (BlogDB, $Blogname_Request, $BlogDB_Link) or die("Couldn't open ".BlogDB.": ".mysql_error());;
    mysql_close ($BlogDB_Link);
    while ($newblogname = mysql_fetch_array ($myblogname))
    {
    $thisblogname = $newblogname[option_value];
    }
    return ($thisblogname);
    }
    function aggregate($table,$title)
    {
    print "<h2>".$title."</h2>";
    $BlogDB_Request = "SELECT *
    FROM
    ".$table."
    ORDER BY
    post_date DESC
    LIMIT 0 , 5";
    $BlogDB_Link = mysql_connect (Host,User,Password);
    $posts = mysql_db_query (BlogDB, $BlogDB_Request, $BlogDB_Link) or die("Couldn't open ".BlogDB.": ".mysql_error());;
    mysql_close ($BlogDB_Link);
    while ($post = mysql_fetch_array ($posts))
    {
    $title = $post[post_title];
    $url = "<a href="".$post[guid]."">";
    print "".$url.$title."</a>
    ".chr(13);
    }
    }
    $BlogID_Request = "SELECT *
    FROM
    wp_blogs
    ORDER BY
    wp_blogs.blog_id ASC
    LIMIT 0 , 1000";
    $BlogDB_Link = mysql_connect (Host,User,Password);
    $blogID = mysql_db_query (BlogDB, $BlogID_Request, $BlogDB_Link) or die("Couldn't open ".BlogDB.": ".mysql_error());;
    mysql_close ($BlogDB_Link);
    while ($blogIDs = mysql_fetch_array ($blogID))
    {
    $thisblogID = $blogIDs[blog_id];
    $blog = "wp_".$thisblogID."_posts";
    $thisblogname = thisblogname($thisblogID);
    aggregate($blog,$thisblogname);
    // aggregate($blog,'');
    }
    ?>
    <?php endwhile; ?>
    <p align="center"><?php posts_nav_link(' - ','« Prev','Next »') ?>
    <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.
    <?php endif; ?>
    </div><!-- end id:content-main -->
    <?php get_sidebar();?>
    <?php get_footer();?>

    Feel free to comment and add any features or tell me ways in which this could be improved :)

  2. andrea_r
    Moderator
    Posted 17 years ago #

    Instead of putting your database details in a file people may be able to access, why not call in the wp-config.php file?

  3. demonicume
    Member
    Posted 17 years ago #

    any more work being done on this? i dropped the blogroll blogroll and added a list-all-blog plugin. does this work better?

  4. drmike
    Member
    Posted 17 years ago #

    I haven't tried it.

    Gotta admit that I would just use the wpmu sitewide feed with fetch_rss and a custom template.

    I do note that the OP isn't doing a check for blog status like public/private, spam, archived, etc. That may be an issue.

  5. lunabyte
    Member
    Posted 17 years ago #

    Or including the blog header, so I have no idea how they're running WP functions without bringing in the files for them.

  6. suleiman
    Member
    Posted 17 years ago #

    folks, this is a page template no?

    Which should mean that header.php is still called.

    Which should mean the includes are still there.

    N'est pas?

  7. lunabyte
    Member
    Posted 17 years ago #

    Damn, you're right.

    So what's up with making a db connection when wpdb already exists?

  8. andrea_r
    Moderator
    Posted 17 years ago #

    That's kinda what I asked...

  9. lunabyte
    Member
    Posted 17 years ago #

    Yeah, kinda.

  10. hwz
    Member
    Posted 16 years ago #

    tried on my WPMU , but didnt see anything on my template when rendered.am i supposed to enable something in the template code?

About this Topic