Not signed in (Sign In)

Vanilla 1.1.2 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorthe_dave
    • CommentTimeJul 11th 2008
     permalink
    I've got the <a href="http://www.arnebrachhold.de/projects/wordpress-plugins/google-xml-sitemaps-generator/">Google Sitemap Generator</a> WordPress plugin version 3.1.0.1 working on Lyceum 1.0.3. You can install it as a system plugin and it will allow each blog to create it's own site map. There are some issues. You need to make sure you specify a different sitemap.xml name for each blog so they don't overwrite each other. Also it's best to turn off the automatic creation of robots.txt because each different blog will overwrite it to only point at its sitemap.

    All I did was modify the query againt the database in sitemap-core.php to retrieve the posts to use a join in order to extract only the posts from a particular blog. To do this I modified just the BuildSitemap function of the GoogleSitemapGenerator class.

    I changed the first line of the function to include the global variable $blog:

    function BuildSitemap() {
    global $wpdb, $posts, $wp_version, $blog;

    I then defined a variable $join to include the two inner joins necessary to find posts only belonging to a single blog. I added this before the $sql variable was defined, and then made sure to add the join variable to the query before the beginning of the WHERE clause.

    $join="INNER JOIN post2cat ON (post2cat.post_id = posts.ID) INNER JOIN categories ON (post2cat.category_id = categories.cat_ID)";

    $sql="SELECT `ID`, `post_author`, `post_date`, `post_date_gmt`, `post_status`, `post_name`, `post_modified`, `post_modified_gmt`, `post_parent`, `post_type` $postPageStmt FROM `" . $wpdb->posts . "` $join WHERE ";

    I added the appropriate where clause to only select posts from the active blog right before the ORDER BY clause is defined:

    $where.=" AND categories.blog = '$blog'"; // query for just the active blog
    $where.=" AND post_password='' ORDER BY post_modified DESC";

    $sql .= $where;

    I also made sure to modify the post count query to contain the $join variable:

    $postCount = intval($wpdb->get_var("SELECT COUNT(*) AS cnt FROM `" . $wpdb->posts . "` $join WHERE ". $where,0,0));

    To get it working I also had to add a function to functions.php:

    function wp_load_alloptions() {
    global $wpdb;
    global $blog;

    $alloptions = wp_cache_get( 'alloptions', 'options' );

    if ( !$alloptions ) {
    //$suppress = $wpdb->suppress_errors();
    if ( !$blogoptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes' AND blog = '$blog'" ) )
    $blogoptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE blog = '$blog'" );
    $blogoptions = array();
    $systemoptions = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE option_domain = 'system'");
    //$wpdb->suppress_errors($suppress);
    $alloptions_db = array_merge($blogoptions, $systemoptions);
    //$alloptions = array();
    foreach ( (array) $alloptions_db as $o )
    $alloptions[$o->option_name] = $o->option_value;
    wp_cache_add( 'alloptions', $alloptions, 'options' );
    }
    return $alloptions;
    }

    I also grabbed cron.php from a newer version of wordpress and put it in the wp-includes directory. Adding cron.php is only necessary if you enable the option to build the sitemap as a background process.
    • CommentAuthorjohn
    • CommentTimeOct 15th 2008
     permalink
    Wow, thanks the_dave!