Advertisement
Guest User

ah_recent_posts_mu

a guest
Nov 9th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. Plugin Name: WordPress MU Recent Posts
  5. Plugin URI: http://atypicalhomeschool.net/wordpress-plugins/
  6. Description: Retrieves a list of the most recent posts in a WordPress MU installation. Based on (Andrea - fill this in)
  7. Author: Ron Rennick
  8. Author URI: http://atypicalhomeschool.net/
  9. */
  10.  
  11. /*
  12. Version: 0.31
  13. Update Author: Sven Laqua
  14. Update Author URI: http://www.sl-works.de/
  15. */
  16.  
  17. /*
  18. Version: 0.32
  19. Update Author: MagicHour
  20. Update Author URI: http://wiki.thisblueroom.net/wiki/Wordpress_MU_sitewide_recent_posts_plugin
  21. */
  22.  
  23. /*
  24. Parameter explanations
  25. $how_many: how many recent posts are being displayed
  26. $how_long: time frame to choose recent posts from (in days)
  27. $titleOnly: true (only title of post is displayed) OR false (title of post and name of blog are displayed)
  28. $begin_wrap: customise the start html code to adapt to different themes
  29. $end_wrap: customise the end html code to adapt to different themes
  30.  
  31. Sample call: ah_recent_posts_mu(5, 30, true, '<li>', '</li>'); >> 5 most recent entries over the past 30 days, displaying titles only
  32. */
  33. function ah_recent_posts_mu($how_many, $how_long, $titleOnly, $begin_wrap, $end_wrap) {
  34. global $wpdb;
  35. $counter = 0;
  36.  
  37. // get a list of blogs in order of most recent update. show only public and nonarchived/spam/mature/deleted
  38. $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE
  39. public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND
  40. last_updated >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
  41. ORDER BY last_updated DESC");
  42.  
  43. if ($blogs) {
  44. foreach ($blogs as $blog) {
  45. // we need _posts and _options tables for this to work
  46. $blogOptionsTable = "wp_".$blog."_options";
  47. $blogPostsTable = "wp_".$blog."_posts";
  48. $options = $wpdb->get_results("SELECT option_value FROM
  49. $blogOptionsTable WHERE option_name IN ('siteurl','blogname')
  50. ORDER BY option_name DESC");
  51. // we fetch the title and ID for the latest post
  52. $thispost = $wpdb->get_results("SELECT ID, post_title
  53. FROM $blogPostsTable WHERE post_status = 'publish'
  54. AND post_type = 'post' AND post_date >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
  55. ORDER BY id DESC LIMIT 0,1");
  56. // if it is found put it to the output
  57. if($thispost) {
  58. // get permalink by ID. check wp-includes/wpmu-functions.php
  59. $thispermalink = get_blog_permalink($blog, $thispost[0]->ID);
  60. if ($titleOnly == false) {
  61. echo $begin_wrap.'<a href="'.$thispermalink
  62. .'">'.$thispost[0]->post_title.'</a> <br/> by <a href="'
  63. .$options[0]->option_value.'">'
  64. .$options[1]->option_value.'</a>'.$end_wrap;
  65. $counter++;
  66. } else {
  67. echo $begin_wrap.'<a href="'.$thispermalink
  68. .'">'.$thispost[0]->post_title.'</a>'.$end_wrap;
  69. $counter++;
  70. }
  71. }
  72. // don't go over the limit
  73. if($counter >= $how_many) {
  74. break;
  75. }
  76. }
  77. }
  78. }
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement