WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [closed] Aggregating Recent Posts to Parent Site in Multisite Install (46 posts)

  1. rbickett
    Member
    Posted 3 years ago #

    I am creating a network of sites in WP 3.0 multi-site. I'd like the parent site to just show widgets that display the recent posts from each of the sites within the network. Can you recommend a good plugin for this or a recommended strategy for the setup?

    Thanks!

  2. dgilmour
    Member
    Posted 3 years ago #

    Maybe take a look at adding BuddyPress on top of your multi-site network? With that, you can go further with an "Activity stream" showing latest posts, comments and more. Other widgets can be used to show who's currently, or was recently, online. I use it this way at edubuzz.org.

  3. There used to be stand-alone widget for exactly this, but they are in need of updating.

    I have one on the way.

  4. raskull
    Member
    Posted 3 years ago #

    Here's one easy, albeit not super-efficient way:

    Drag an rss widget for each site into the sidebar (or any widgetized area in your theme) and enter its feed url.

    Get each site's feed url by clicking on the rss icon displayed on the site and copying the resulting url from the location bar.

    If you don't see an rss icon (and for more info on feeds) read this:
    http://codex.wordpress.org/WordPress_Feeds#Finding_Your_Feed_URL

  5. redleafnetwork
    Member
    Posted 3 years ago #

    @rbickett
    Try this theme. It might work for you in conjunction with raskull's RSS concept. I, too, am looking for a 'portal' to my network of blogs.
    http://bavotasan.com/downloads/feed-me-seymour-free-wordpress-theme/
    http://themes.bavotasan.com/our-themes/basic-themes/feed-me-seymour/

  6. Magazine themes make great portals.

  7. raskull
    Member
    Posted 3 years ago #

    If you do use rss, you might want to speed up the cache clearing, otherwise new posts might take quite a while to appear. Put this in your functions file:

    // speed up rss cache -- 1800 seconds = 1/2 hour
    add_filter( 'wp_feed_cache_transient_lifetime', create_function('$fixrss', 'return 1800;') )
  8. redleafnetwork
    Member
    Posted 3 years ago #

    Thanks raskull :-)

  9. rbickett
    Member
    Posted 3 years ago #

    Wow! Thanks to everyone for the great suggestions!

  10. intragenesis
    Member
    Posted 3 years ago #

    Yeah, same thing here. I'm wanting the main content of my parent site to pull a list of the most recent posts from several (all) child sites. When I mean posts, I mean it in the context of "news articles" written on the child sites.

    The idea here is the parent site is like a county page and the child sites are like a town. When someone posts to any town I need the parent/county page to display the recent posts made from all of the towns, not just one (so I don't think the rss thing will work here).

    I guess the parent could be coded with php to fetch the recent articles but since each "city" has its own table, and there could be 200 cities, this makes for a long db query. Seems this feature would be the main purpose of the multisite feature?

    (This gets into another issue, displaying on the parent site a list of current events retrieved from child calendars.)

    Any ideas?

  11. raskull
    Member
    Posted 3 years ago #

    You can use as many rss widgets as you want -- one for each town. Each widget lets you choose up to 20 posts from the town site. (I should mention these are post titles, with links, not the post content.)

    However that is just a quick and dirty solution. But it's not too hard to use other rss aggregation tools to do this more efficiently.

    For calendars, you might look into giving each town a google calendar, then merging the rss feeds from the calendars. Then use the google calendar api to display the events (there are plugins that do this).

  12. marikamitsos
    Member
    Posted 3 years ago #

    @ raskull
    Are you (or anyone else) aware of such an aggregator?
    Ideally (IMHO) it would have to pick the excerpt with an image from the latest network posts from each site(blog) and display them grouped by blog or even better mixed in a descending time order linking to the original post.
    Thanx

  13. raskull
    Member
    Posted 3 years ago #

    You could google for rss aggregator widgets and plugins, but I've had the best luck starting from scratch using SimplePie.

    SimplePie also offers SimplePie Plugin for WordPress which I haven't tried.

    There's a product mentioned in this thread, but I don't know anything about it.

  14. dgilmour
    Member
    Posted 3 years ago #

    This freshly baked plugin might help too: http://wordpress.org/extend/plugins/diamond-multisite-widgets/

  15. raskull
    Member
    Posted 3 years ago #

    There is a difference between using rss to pull the content and querying the database of the multisite install.

    I myself am hoping to get more information about the advisability of and alternatives to querying the database if you have a large number of blogs.

    The plugin above, and all the others I've seen, use the function get_blog_list, which has been deprecated for its "suicidal" tendencies.

    I will start a new thread on that.

  16. marikamitsos
    Member
    Posted 3 years ago #

    I hear you both.
    I would love the result dgilmour but would am not "suicidal". :-)
    I will give it atry at a test site but this would have no more than 10 blogs or so.

    @ raskull: Please post the link to the thread here so we could follow.
    Thanx

  17. raskull
    Member
    Posted 3 years ago #

    Here's the thread I started. Hopefully an expert will weigh in:

    suicidal multisite database queries

  18. redleafnetwork
    Member
    Posted 3 years ago #

    I may end up using this theme using simplepie for a while until I can find a better way.

    http://templatic.com/news/aggegator-all-your-feeds-at-your-website-front

    Demo: http://templatic.com/demo/aggregator/

  19. @raskull querying the db & caching is a whole lot less expensive than using rss to pull information from across the site. Not only that, the rss pull from within the same install is way less efficient. you're going out to the internet and all the way back again, in addition to querying the site.

    I rarely recommend using rss feeds internally. It can easily pull down your site.

    The plugin above, and all the others I've seen, use the function get_blog_list, which has been deprecated for its "suicidal" tendencies.

    And that's why I said we had a new one on the way....

    @marikamitsos had you looked at the sitewide tags plugin?
    http://wordpress.org/extend/plugins/wordpress-mu-sitewide-tags/
    It pulls full posts, so if you really wanted just headlines, use that on a tags blog, then pull the ONE rss feed to the main page on the main site.

    Problem solved.

  20. raskull
    Member
    Posted 3 years ago #

    I don't seem to be getting an answer to my questions though. What is the safe method for users with a lot of blogs?

    I'm not asking for a plugin; I'm asking for the best method to achieve what I'm after. If it is not rss and it is not get_blog_list and it is not transients api... then what is it?

    Is it a secret?

  21. Lol, no.

    It's called a global table.

  22. raskull
    Member
    Posted 3 years ago #

    So something like this? http://premium.wpmudev.org/project/post-indexer

    "This is one heck of a powerful plugin as it indexes all posts on your site into a global table that can be queried for lists of recent posts, etc..."

  23. Yeah, that's one way.

    have a look at the sitewide tags plugin and see how it copies the data it needs.

    http://wordpress.org/extend/plugins/wordpress-mu-sitewide-tags/

  24. Denise Barnes
    Member
    Posted 3 years ago #

    Andrea - when will your widget for this purpose be available?

  25. when I get around to nagging Ron to write the release post & release it already. :D

    it's on the list - it's just a loooong list.

  26. saturdayplace
    Member
    Posted 3 years ago #

    It's amazing that I didn't need this functionality until about a week ago (when the OP was written), and Andrea promises imminent release of the very widget to ease my woes. I don't want to nag, but I would like to add my voice to this thread in hopes of nudging the release forward.

  27. g0dlike
    Member
    Posted 3 years ago #

    Let me contribute with some code to solve this problem without any plugins. :)
    Put this into latest_posts.php and, in functions.php in your theme folder add on top require('latest_posts.php');

    Hope this helps! ;)

    <?php
    /*
    Parameters
    ==========
    
    $how_many (integer): how many recent posts are being displayed.
    $how_long_days (integer): time frame to choose recent posts from (in days).
    $how_many_words (integer): how many post's teaser are being displayed. Count by word. Default value are 50 words.
    $remove_html (boolean): set true to remove any html tag within the post.
    $sort_by (string - post_date/post_modified): You can short the lattest post by positing date (post_date) or posting update (post_modified).
    
    Return
    ======
    
    ID
    post_url
    post_title
    post_content
    author_url
    author_name
    post_date
    post_time
    comment_count
    */
    function wpmu_latest_post($how_many = 10, $how_long_days = 30, $how_many_words = 50, $more_text = "[...]", $remove_html = true, $sort_by = 'post_date') {
    	global $wpdb;
    
    	//first, gat all blog id
    	$query = "SELECT blog_id FROM $wpdb->blogs WHERE blog_id !='1'";
    	$blogs = $wpdb->get_col($query);
    
    	if ($blogs) {
    		//we use blog id to loop post query
    		foreach ($blogs as $blog) {
    			$blogPostsTable = 'wp_'.$blog.'_posts';
    
    			$db_query = "SELECT $blogPostsTable.ID,
    						$blogPostsTable.post_author,
    						$blogPostsTable.post_title,
    						$blogPostsTable.guid,
    						$blogPostsTable.post_date,
    						$blogPostsTable.post_content,
    						$blogPostsTable.post_modified,
    						$blogPostsTable.comment_count
    						FROM $blogPostsTable WHERE $blogPostsTable.post_status = 'publish'
    						AND $blogPostsTable.post_date >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long_days DAY)
    						AND $blogPostsTable.post_type = 'post'";
    
    			$thispos = $wpdb->get_results($db_query);
    
    			foreach($thispos as $thispost) {
    				if($sort_by == 'post_date') {
    					$order = $thispost->post_date;
    				}
    				else{
    					$order = $thispost->post_modified;
    				}
    
    				$post_dates[]			= $order;
    				$post_guids[$order]		= $thispost->guid;
    				$blog_IDs[$order]		= $blog;
    				$post_IDs[$order]		= $thispost->ID;
    				$post_titles[$order]	= $thispost->post_title;
    				$post_authors[$order]	= $thispost->post_author;
    				$post_contents[$order]	= $thispost->post_content;
    				$comments[$order]		= $thispost->comment_count;
    			}
    		}
    
    		rsort($post_dates);
    		$union_results	= array_unique($post_dates);
    		$ResultArray	= array_slice($union_results, 0, $how_many);
    
    		foreach ($ResultArray as $date) {
    			$ID					= $post_IDs[$date];
    			$id_author			= $post_authors[$date];
    			$post_url			= get_blog_permalink($blog_IDs[$date], $ID);/*$post_guids[$date];*/
    			$post_title			= $post_titles[$date];
    			$post_content		= $post_contents[$date];
    			$post_date			= mysql2date(get_option('date_format'), $date);
    			$post_time			= mysql2date(get_option('time_format'), $date);
    			$total_comment		= $comments[$date];
    			$user_info			= get_userdata($id_author);
    			$author_blog_url	= get_blogaddress_by_id($user_info->primary_blog);
    			$author_url			= $user_info->user_url;
    			$author_email		= $user_info->user_email;
    
    			if($user_info->first_name) {
    				$author_name = $user_info->first_name.' '.$user_info->last_name;
    			}
    			else{
    				$author_name = $user_info->nickname;
    			}
    
    			if($remove_html) {
    				$post_content = wpmu_cleanup_post($post_content);
    			}
    
    			$results = array();
    
    			$results['ID']				= $ID;
    			$results['post_url']		= $post_url;
    			$results['post_title']		= $post_title;
    			$results['post_content']	= wpmu_cut_article_by_words($post_content, $how_many_words);
    			if ($results['post_content'] != $post_content)
    				$results['post_content'] .= sprintf('  <a href="%s">%s</a>', $post_url, $more_text);
    			$results['author_blog_url'] = $author_blog_url;
    			$results['author_url'] 		= $author_url;
    			$results['author_email']	= $author_email;
    			$results['author_name'] 	= $author_name;
    			$results['post_date']		= $post_date;
    			$results['post_time']		= $post_time;
    			$results['comment_count'] 	= $total_comment;
    
    			$returns[] = $results;
    		}
    
    		$latest_posts = wpmu_bind_array_to_object($returns);
    		return $latest_posts;
    	}
    }
    
    function wpmu_bind_array_to_object($array) {
    	$return = new stdClass();
    
    	foreach ($array as $k => $v) {
    		if (is_array($v)) {
    			$return->$k = wpmu_bind_array_to_object($v);
    		}
    		else {
    			$return->$k = $v;
    		}
    	}
    	return $return;
    }
    
    function wpmu_cut_article_by_words($original_text, $how_many) {
    	$word_cut = strtok($original_text," ");
    
    	$return = '';
    
    	for ($i=1;$i<=$how_many;$i++) {
    		$return	.= $word_cut;
    		$return	.= (" ");
    		$word_cut = strtok(" ");
    	}
    
    	$return .= '';
    	return $return;
    }
    
    function wpmu_cleanup_post($source) {
    	$replace_all_html = strip_tags($source);
    	$bbc_tag = array('/\[caption(.*?)]\[\/caption\]/is');
    	$result = preg_replace($bbc_tag, '', $replace_all_html);
    
    	return $result;
    }
    ?>
  28. pcheick
    Member
    Posted 3 years ago #

    @g0dlike - looks really cool! ...now, if that was a plugin with some fields to control the parameters you define in how many, how long and how often... ;-)

  29. lstewartiii
    Member
    Posted 3 years ago #

    @g0dlike Just to clarify what your instructions were

    Put this into latest_posts.php and, in functions.php in your theme folder add on top require('latest_posts.php');

    YOu want us to

    • Create a file called latest_post.php and past the code above into it
    • Save the file as wp-content/themes/yourtheme/functions/latest_post.php/
    • open wp-content/themes/yourtheme/functions.php and add require('latest_posts.php'); or in my case require_once ($functions_path . 'latest_posts.php'); // latestposts
    • I tried your code, first with the require as you had it and this is the error it gave:

      Warning: main(latest_posts.php) [function.main]: failed to open stream: No such file or directory in /nfs/c07/h03/mnt/103866/domains/mydomain.com/html/wp-content/themes/mytheme/functions.php on line 13
      
      Warning: main(latest_posts.php) [function.main]: failed to open stream: No such file or directory in /nfs/c07/h03/mnt/103866/domains/mydomain.com/html/wp-content/themes/mytheme/functions.php on line 13
      
      Fatal error: main() [function.require]: Failed opening required 'latest_posts.php' (include_path='.:/usr/local/php-4.4.8-1/share/pear') in /nfs/c07/h03/mnt/103866/domains/mydomain.com/html/wp-content/themes/mytheme/functions.php on line 13

      and when I tried it with the path corrected, I got this error

      Warning: main(/nfs/c07/h03/mnt/103866/domains/mydomain.com/html/wp-content/themes/mytheme/functions/latest_posts.php) [function.main]: failed to open stream: No such file or directory in /nfs/c07/h03/mnt/103866/domains/mydomain.com/html/wp-content/themes/mytheme/functions.php on line 21
      
      Fatal error: main() [function.require]: Failed opening required '/nfs/c07/h03/mnt/103866/domains/mydomain.com/html/wp-content/themes/mytheme/functions/latest_posts.php' (include_path='.:/usr/local/php-4.4.8-1/share/pear') in /nfs/c07/h03/mnt/103866/domains/mydomain.com/html/wp-content/themes/mytheme/functions.php on line 21

      If I messed up somewhere please clarify for me. And added info; i changed the names of my domain and theme for security reason but the errors are still the same.

  30. Phoat
    Member
    Posted 3 years ago #

    @g0dlike

    While I understand some of the code you posted, I'm a little lost in how you would go about using it. How do you display the posts that you queried from the different blogs? My php skills are minimal at best.

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic