The MU forums have moved to WordPress.org

Sitewide multiwidget (3 posts)

  1. Romik84
    Member
    Posted 14 years ago #

    Hi,

    I would like to add sitewide function of plugin http://wpmudevorg.wordpress.com/project/Sitewide-Multi-Widget to the template manually. I have tried following:

    <?php

    function sitewide_recent_posts($args) {

    global $wpdb;
    $options = get_option('sitewide_recent_posts');
    $tags_blog = get_site_option( '1' );

    $new_id_post = (int) $_POST["ds_sitewide_output_widget-blog_id"];

    $wpdb->hide_errors();
    $found_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE blog_id = '$new_id_post' AND public='1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0'" ); // blogname?
    if($found_id)
    { $options['1'] = (int) $_POST["ds_sitewide_output_widget-blog_id"];
    } else {
    $options['1'] = get_site_option( '1' );
    }
    $wpdb->show_errors();

    update_option('sitewide_recent_posts', $options);

    $options = get_option('sitewide_recent_posts');

    // These lines generate our output.

    $featured_blogs = '1'; // Clone multiple panel outputs such as ...
    // $featured_blogs = array($options['blog_id'],63);
    if (!is_array($featured_blogs)) $featured_blogs= array($featured_blogs); // hiccup
    foreach($featured_blogs as $featured_blog) {
    switch_to_blog($featured_blog); // minimize use of switch_to blog/restore_current_blog hence several widgets in one multiwidget
    $tag_name_variable = $options['tagname']; // return all matches to any tags seperated by a comma
    $category_name_variable = $options['catname']; // assign the variable as current category
    $number_variable = $options['limit']; // how many?
    // http://codex.wordpress.org/Template_Tags/query_posts a zillion combos
    $query_string = array(
    'tag' => $tag_name_variable,
    'category_name' => $category_name_variable,
    'showposts' => $number_variable
    );
    $query = new WP_Query($query_string);
    if ($query->have_posts()) :

    echo '<ul style="margin-top:5px;">';
    while ($query->have_posts()) : $query->the_post();
    echo '<li class="ra-recent-posts">';
    // whatever you can do to a loop, do it here
    {
    ?>
    <?php echo get_avatar( get_the_author_id(), '40', $default = 'http://blogatize.net/wp-content/themes/blogatize-chameleon/design/avatar.jpg' ); ?>
    <?php }
    { ?>
    " title="Permanent Link to <?php if ( get_the_title() ) the_title(); else the_ID(); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?>
    <small>
    <?php
    }
    echo '<span style="font-weight:normal;">';

    the_time('M jS, Y');
    echo '</span> by '; the_author();

    echo '</small>';
    endwhile;
    echo '';
    endif;
    }
    }
    ?>
    <?php sitewide_recent_posts('','',''); ?>

    When I have in footer function <?php wp_list_pages('title_li='); ?> of a blog I got pages of main blog. What should I fix?

    Thanks.

  2. dsader
    Member
    Posted 14 years ago #

    Romik84, what you have there is a mess.

    What is get_site_option( '1' )? Should be a tags_blog_id in there somewhere? Anyway, what should you fix? Start over.

    Plan A: Sitewide Workflow
    Do you have Donncha's Site Wide Tags Pages plugin up and running? How do you know? Does the plugin http://wpmudevorg.wordpress.com/project/Sitewide-Multi-Widget work without edits as intended? Verify this first. Without the sitewide plugin, it is nothing more than the run of the mill recent posts, tagcloud, or archives widgets in WP.

    Plan B: Featured Blog Workflow
    // begin with the blog you are on
    switch_to_blog($id);
    //do stuff to feature content from a new blog $id
    restore_current_blog();
    // continue with the blog you are on

    PS
    Use a free pastebin url for posting code you'd like others to see/test.

  3. Romik84
    Member
    Posted 14 years ago #

    dsader, thanks.

    I have added the <?php restore_current_blog(); ?> function right after that code and it works now. Thanks again.

About this Topic