The MU forums have moved to WordPress.org

sitewide recent comments anyone? (3 posts)

  1. DrLightman
    Member
    Posted 12 years ago #

    Do you know of a reliable recent comments plugin to grab X latest recent comments across all blogs fo the network?

    ( that wouldn't be this: http://wpmudevorg.wordpress.com/project/Sitewide-recent-comments )

  2. Matt Lynham
    Member
    Posted 12 years ago #

    I have the same problem, have tried modifying some code I found that displays latest posts across all blogs but isn't having any of it!

  3. Matt Lynham
    Member
    Posted 12 years ago #

    Looks like it may just be me and you DrLightman, this is the code I had to show all recent posts, I've tried to modify it in many ways but I couldn't get it to work, take a look and if you have any ideas please let me know :)

    /*
    Parameter explanations
    $how_many: how many recent posts are being displayed
    $how_long: time frame to choose recent posts from (in days)
    $titleOnly: true (only title of post is displayed) OR false (title of post and name of blog are displayed)
    $begin_wrap: customise the start html code to adapt to different themes
    $end_wrap: customise the end html code to adapt to different themes
    
    Sample call: ah_recent_posts_mu(5, 30, true, '<li>', '</li>'); >> 5 most recent entries over the past 30 days, displaying titles only
    */
    function ah_recent_posts_mu($how_many, $how_long, $titleOnly, $begin_wrap, $end_wrap) {
    	global $wpdb;
    	$counter = 0;
    
    	// get a list of blogs in order of most recent update. show only public and nonarchived/spam/mature/deleted
    	$blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE
    		public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND
    		last_updated >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
    		ORDER BY last_updated DESC");
    
    	if ($blogs) {
    		foreach ($blogs as $blog) {
    			// we need _posts and _options tables for this to work
    			$blogOptionsTable = "wp_".$blog."_options";
    		    	$blogPostsTable = "wp_".$blog."_posts";
    			$options = $wpdb->get_results("SELECT option_value FROM
    				$blogOptionsTable WHERE option_name IN ('siteurl','blogname')
    				ORDER BY option_name DESC");
    		        // we fetch the title and ID for the latest post
    			$thispost = $wpdb->get_results("SELECT ID, post_title
    				FROM $blogPostsTable WHERE post_status = 'publish'
    				AND post_type = 'post' AND post_date >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
    				ORDER BY id DESC LIMIT 0,1");
    			// if it is found put it to the output
    			if($thispost) {
    				// get permalink by ID.  check wp-includes/wpmu-functions.php
    				$thispermalink = get_blog_permalink($blog, $thispost[0]->ID);
    				if ($titleOnly == false) {
    					echo $begin_wrap.'<a href="'.$thispermalink
    					.'">'.$thispost[0]->post_title.'</a> <br /> by <a href="'
    					.$options[0]->option_value.'">'
    					.$options[1]->option_value.'</a>'.$end_wrap;
    					$counter++;
    					} else {
    						echo $begin_wrap.'<a href="'.$thispermalink
    						.'">'.$thispost[0]->post_title.'</a>'.$end_wrap;
    						$counter++;
    					}
    			}
    			// don't go over the limit
    			if($counter >= $how_many) {
    				break;
    			}
    		}
    	}
    }

About this Topic

  • Started 12 years ago by DrLightman
  • Latest reply from Matt Lynham