WordPress.org

Ready to get started?Download WordPress

Forums

recent posts in wordpress multisite without rss (3 posts)

  1. dallasm
    Member
    Posted 3 years ago #

    I'm currently displaying the 3 most recent posts and RSS links to 9 of my sites on multisite: I'm using a shortcode for the excellent "better rss widget" in my sidebar so its replicated across all my sites via my theme.
    I know RSS is an inefficent way to do this.
    I had though about using the "multisite widgets" but I'd rather hardcode the text.
    I've heard about using the switch_to_blog() function in an article that instead proposed doing this:

    function umw_get_blog_posts( $blogid=1, $type='post', $parent=0 ) {
    	global $wpdb;
    	$wpdbobj = clone $wpdb;
    	$wpdb->blogid = $blogid;
    	$wpdb->set_prefix( $wpdb->base_prefix );
    	$query = $wpdb->prepare( "SELECT ID, post_title, post_name
    		FROM $wpdb->posts
    		WHERE post_status='publish'
    		AND post_type='$type'
    		AND post_parent=$parent" );
    	$wpdb = clone $wpdbobj;
    	return $wpdb->get_results( $query, ARRAY_A );
    }

    From this site http://www.htmlcenter.com/blog/wordpress-multi-site-switching-blogs/
    I'm wondering which of these or alternatives would be best.

    Also, because this sidebar is pulled by every page, should I include this in functions or as a seperate page or something to stop it having to be created every time (or won't it need to be anyway?)

    Thanks
    Dallas

  2. Samuel B
    moderator
    Posted 3 years ago #

  3. dallasm
    Member
    Posted 3 years ago #

    Hi, thanks,
    I already use this but its for displaying posts in the feed section on the main blog only
    It works great, but it displays posts in order regardless of blog
    So I use this at my main site
    I also use the multisite recent posts widget which displays the latest post from each blog (not the 10 latest from 1 blog for example)

    But I also want to display the 3 latest from each blog
    I know diamond multisite widgets will do something like this but I want to keep the code small and light and rely on plugins as little as possible (have heaps already)

    You can see each of these working at my site incairns.net.au

Topic Closed

This topic has been closed to new replies.

About this Topic