Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on a school website. The design calls for a collection of largely static pages, but for each class to have a blog which will be updated every few days.

I know nothing about WordPress or PHP (thought I have development experience on other platforms) but I got the static bits of the site, based on a custom theme, up without too many problems.

I set up a page for each class blog but I really wanted the authors to use the blogging engine rather than just continually updating a page. To enable this I switched on multi-site, based on URL, and set up some blogs in the sub-site for each class.

However I'm now stuck on how to make the standard index.php I created for the static pages display blog content instead for certain sections of the site.

I'd also like to add a right-hand widget that will display the most recent three entries from blogs, regardless of what class their from.

Ideally I also need to add a date to the page title for blogs, but not for the static pages on the site.

Anyone help?

EDIT: Index.php code as requested

<div id="column-center">
     <?php if (have_posts()) : while (have_posts()) : the_post();?>
     <p style="font-size:22px;"><?php the_title();?></p>
     <hr class="hr-red" />
     <div style="font-size:13px;">
     <?php the_content(); ?>
     </div>
     <?php endwhile; endif; ?>
     <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
</div>
share|improve this question
    
Please show your current index.php code. –  kaiser Nov 12 '12 at 20:05

1 Answer 1

This can be achieved with the help of a plugin.
A custom, hand coded, solution can be built analyzing and modifying the code of such plugin(s).

Searching for "multisite + widget", I found one plugin of interest.

Multisite Posts

Get posts from another child site in a multisite setup. You can also integrate the plugin into your theme file, very efficient. Offers shortcode and widget for feature usage. Internationalization ready.

Seems well coded, is up to date with the latest WordPress version (3.4.2) and may solve the index.php issue (via shortcode) and the widget too.

Caveat is that each site has to be manually added (1 shortcode/widget per site).


Custom Shortcode to Use with the Plugin

Automates what would be a manually typed list of shortcodes.

add_shortcode( 'blogs_posts', 'wpse_72355_blogs_posts' );

function wpse_72355_blogs_posts( $attr ) 
{
    global $wpdb;
    $blogs = $wpdb->get_results($wpdb->prepare("
        SELECT blog_id
        FROM {$wpdb->blogs}
        WHERE site_id = '{$wpdb->siteid}'
        AND spam = '0'
        AND deleted = '0'
        AND archived = '0'
        AND mature = '0' 
        AND public = '1'
    "));

    $the_blogs_posts = '';

    foreach ($blogs as $blog) 
    {
        $details = get_blog_details( $blog->blog_id );

        $the_blogs_posts .= 'From the site: <a href="' 
            . $details->siteurl . '">' 
            . $details->blogname . '</a><br>';

        $the_blogs_posts .= do_shortcode( 
            '[multisite_posts no="' . $attr['no'] 
            . '" site_id="' . $blog->blog_id . '"]' 
            );
    }
    return $the_blogs_posts; 
}

The foreach ($blogs as $blog) could be adapted to work like this:

$original_blog_id = get_current_blog_id();

foreach ($blogs as $blog) 
{
    switch_to_blog( $blog->blog_id );

    // http://codex.wordpress.org/Function_Reference/get_posts
    $posts_array = get_posts( $args ); 

    // Iterate through $posts_array and build the output
}
switch_to_blog( $original_blog_id );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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