AHP Sitewide Recent Posts plugin for Wordpress MU

by Aziz Poonawalla on September 17, 2008

Building on the venerable Recent Posts plugin by Ron and Andrea, I have created an extended version that offers a lot more user control over output, including gravatar support. The basic features are:

  • excludes posts on main blog (blog ID = 1)
  • excludes first posts (Hello, world) on user blogs (post ID = 1)
  • option to show gravatar support (24px). Gravatar links to posts by user on their blog.
  • option to show post excerpt. User can specify excerpt length with extra argument. Option to capitalize 1st five words of excerpt for readability.
  • option to show post author name
  • option to show post date
  • option to show post comment count
  • all dispay options can be selectively toggled on or off using a single bitmask parameter, permitting very flexible and customizable usage (256 possible configurations!)
  • numerous other display and formatting options can be easily edited in source code using global vars

The argument list:

  • $how_many: how many recent posts are being displayed
  • $how_long: time frame to choose recent posts from (in days)
  • $optmask: bitmask for various display options (default: 255)
    • 1; // gravatar
    • 2; // date
    • 4; // author name
    • 8; // comment count
    • 16; // blog name
    • 32; // post name
    • 64; // post excerpt
    • 128; // excerpt capitalization
  • $exc_size: size of excerpt in words (default: 30)
  • $begin_wrap: start html code (default: <li class=”ahp_recent-posts”>)
  • $end_wrap: end html code to adapt to different themes (default: </li>)

To use the bitmask option, simply add the numeric codes for the display options you want together. For example, suppose you only want gravatar, post name, and date – then the bitmask would be 1+2+32 = 35. Using a bitmask in this way, you can turn on or off any combination of display options above, using only a single function argument.

The latest version (0.6) of this plugin is at WPMUDEV with a more complete description, installation instructions, screenshot, and sample function call. You can see also see the plugin in action at Talk Islam, under the sidebar section titled “Recent Journals”.

screenshot of AHP Recent Posts plugin for WPMU

screenshot of AHP Recent Posts plugin for WPMU

{ 103 comments… read them below or add one }

1 ovidiu 09.25.08 at 6:17 am

hello.
where would I install it? mu-plugins? or can I put it into the plugins folder? And let other blogs use it too? or is it made for the main blog only?

2 Aziz Poonawalla 09.25.08 at 7:23 am

its really intended for use on the main blog, but there’s no reason that a sub-blog couldn’t also use it. The plugin was intended for use in mu-plugins so if its placed there then any blog can make the function call. however you certainly could enable it on a per-blog basis if you prefer.

3 wep 09.25.08 at 10:22 am

i have ahp recent post plugin and anarchy media plugin, when add link of video of youtube with anarchy media, the video appears, like excluding the video so that he does not appear in front page?

with ahp recent posts video no appears but yes one SPACE IN WHITE, like excluding the videos?

4 Aziz Poonawalla 09.25.08 at 10:35 am

my plugin strips out the HTML tags from the post excerpt, so any embedded content will also get stripped out. Its a necessary feature because otherwise the list of recent posts might screw up formatting for the rest of the site. You can edit the plugin to disable the HTML-stripping if you like, it’s on line 181, which currently reads,

$thiscontent = strip_tags( $thispost[0]->post_content );

Change that line to read,

$thiscontent = $thispost[0]->post_content;

However note that you might be in for some strange output results…

5 Elizabeth Edwards 09.26.08 at 7:49 pm

This looks like it could be great but I cant get it to work…what am I missing?

I uploaded it to mu plugin folder.
Popped the code <?php ahp_recent_posts_dev(5, 30, 20 , ”, ”,7); ?> onto the template to test it (home.php page)

I got this…

Fatal error: Call to undefined function ahp_recent_posts_dev() in /home/****/public_html/wpmu/wp-content/themes/home/home.php on line 36

What havent I done lol?

6 Aziz Poonawalla 09.26.08 at 11:29 pm

you know what? you just caught an error in my plugin documentation. The actual function call should be ahp_recent_posts(); , not ahp_recent_posts_dev();

Please omit the _dev in your function call and it will work just fine. I apologise. I will correct that error in the documentation at next release.

7 Elizabeth Edwards 09.27.08 at 1:32 pm

IT WORKS!! lol Thank you SO much it is just what I wanted! Now a really silly question…. If I want several peoples side by side, or on a grid, can I do that? Or… how can I just put them neater than they are at present.. http://theartnetwork.co.uk/wpmu ? I will be showing about 30 and where they are now, on the front page…

One last thing.. (sorry) I cane here last night in Firefox and it went on fine, but tonight in Firefox the form to put my name etc disappeared and so I have had to use IE

8 Aziz 09.28.08 at 10:24 am

Its easy to format the function to let you format the display – note that there are arguments for HTML before and after each entry. I usually use list item containers li and /li for these arguments so that the output is formatted as a list. You could also use TD and /TD to format as a table (in fact I need to add an argument that lets you select not just N posts, but an offset.. hmm… ). Then you can use CSS to style the output too. The function is very flexible but maximizing the usage will require you to get down into the details of CSS and HTML etc.

9 Elizabeth Edwards 09.28.08 at 4:00 pm

ok totally lost LOL and your li thingies up top dont work, they crashed the page. I will wait until perhaps you or someone can tell me step by step …. Thank you SO much for this though, it is ACE!

Still cant use comments here in Firefox :(

10 Aziz Poonawalla 09.29.08 at 5:45 am

Elizabeth,

the standard way to use the plugin in your template is as follows:


<ul>
<?php ahp_recent_posts(5,30,20,"<li>","</li>",7); ?>
</ul>

note that the LI tags have the left and right angle brackets – those are ESSENTIAL. Also the second LI tag has the slash, which is also essential. If you invoke teh function as above, and surround the function call with the UL tags as I have shown above, then you will end up with a nicely formatted HTML list.

Note, however, that to further customize the output of the function you will need to learn some basic CSS styling. There are plenty of good resources on basic CSS and how to format lists in particular, just google around.

11 wep 09.29.08 at 1:22 pm

$thiscontent = $thispost[0]->post_content; <– mm no is solution for me.

other solution? there is no another way to exclude posts or the videos?

12 Aziz Poonawalla 09.29.08 at 2:55 pm

wep, i dont understand what you mean, did changing that line not work? was there an error message?

Ther emay be some conflict with the media plugin you are using I suggest talking to the author of that one since my plugin is not a very complex one and the problem is more likely to be there than here.

13 wep 09.29.08 at 3:39 pm

without strip_tags sees code in home, front page. i want: NOT post with videos in front page or not some posts in front page.

14 deryk 10.03.08 at 3:05 pm

hello aziz, great plugin work. I’m very interested in using this plugin, but i really need to make it show more than one post per blog. if you give me a hint on how to do it, I can try to do the programming to help you out. This might be a totally new topic, but would it be easy to show the sub blog info within the main blog template rather than within the original blog?
thanks, Deryk

15 Johanes 10.05.08 at 4:32 am

I don’t understand, i put your plugins to mu-plugins folder and then put your code to my templates but there’s nothing displayed

<?php ahp_recent_posts(5,30,20,”",”",7); ?>

16 Aziz Poonawalla 10.15.08 at 6:12 am

wep, I dont think you can use this plugin to exclude posts based on the content. It will pick up all posts, whether you embed video or not. Maybe I am still misunderstanding what you are trying to do?

deryk, that feature is coming, it is on my todo list. It involves modiying the SQL queries. You are free to look at teh source code and suggest a patch for me to integrate if you have time to do so before I get to it. BTW, you can put the function call anywhere you like in your template – i dunno if that answers your second question, if not can you please clarify?

Johanes, you may simply not have any posts in the last 30 days? Its hard to really guess from the information you’ve provided as to why there is no output. You are not getting a php error, it seems, so it is probably your arguments rather than any error.

17 buzz_lightyear 10.16.08 at 5:25 pm

Hi Aziz,
maybe you should check the plugin v0.6 source @ wpmudev.org.
The function there is indeed called \”ahp_recent_posts_dev\”.

thanx for nice plugin anyway
buzz

18 Aziz Poonawalla 10.16.08 at 9:40 pm

buzz, thank you. I just uploaded version 0.6.1 to fix that. Sorry about teh confusion.

19 buzz_lightyear 10.17.08 at 12:27 am

Hi Aziz,
one more remark… ;)

there is one little mistake more, which makes your cool script not properly validated. There should be “span class” instead of “span style”, i think.

//$thisexcerpt = ”.$exc_str
$thisexcerpt = ”.$exc_str

thanx
buzz

20 spmckee 10.20.08 at 6:03 pm

Greetings and thank you!

I am wondering though how I can have it return results from the main blog (id=1)? I removed the line; “AND blog_id != ‘1′” and this did work but only returns one result. Any ideas?

Thanks,
spmckee

21 Aziz 10.21.08 at 9:10 pm

buzz,

argh! ok will need to release another point release version to fix that. If you notice anything else please dont hesitate to drop me an email at apoonawa dash blog at yahoo.

spmckee,

removing the AND blog_id !== 1 is exactly right, though note if you do this, you might only see one result because the main blog updates more often than the sub-blogs. Also check your function arguments for the time period to see if there were any actual posts from the sub blogs therein or not. Note that this plugin does not show more than one post from each recently updated blog, so you will only see one post from each blog updated within the specified time frame.

22 tulgaa 10.25.08 at 12:57 am

Thanks for the wonderful plugin. I have two requests regarding the plugin:
- When I click on the gravatar link, it takes me to http://wpmusite.com/username, which returns 404 error. Correct url should be http://userblog.wpmusite.com/username
- Make plugin ready for the translation. I manually translated it, but some strings, for example “F jS, Y”, doesn’t come out correctly (F is not translated).

Thank you.

23 mark 10.31.08 at 1:10 am

question. is there a way to show more than one users recent post? if the user posts 2 times in the same day, can that be called out? also, if a person comments, i noticed the post automatically moves back up to the top.

24 IdaWebCo 11.11.08 at 8:04 pm

Ditto on the great plugin and thank you for it! I also have the problem reported by tulgaa – I need the gravatar to link to http://userblog.wpmusite.com/username but can’t figure out how to hack it. Help anyone?

25 IdaWebCp 11.11.08 at 9:49 pm

I fixed the gravatar author link on about line 220

It did say:
$thisuser_url = $thisbloglink.\”author/\”.$thisuser;

I changed it to:
$thisuser_url = $blog_link.\”author/\”.$thisuser;

and it works great!

26 Aziz Poonawalla 11.12.08 at 6:15 pm

tulga, you’re right, that makes more sense (and thanks IdaWebCp for the patch). I’ll release an updated version along with the CSS fix that buzz mentioned above. Also I am debating whether there would be any interest in a non-WPMU, single-WP version of the plugin?

27 Jake 11.17.08 at 9:46 am

Is there anyway you could show more than 1 recent post per user? Like their 5 most recent posts or something like that?

28 Chaslie 11.18.08 at 8:44 pm

Does the file name of the downloaded plugin have to remain the same when you upload it into the mu_plugins folder? The downloaded file is called ‘1104069568_ahp_recent_posts_0.6′ and the file extension is ‘.1[1] Document’? The reason I ask is that I cannot get this plugin to word in my WPMU 2.6.3. I also changed the name of the file to ‘ahp_recent_posts’ and still no luck. Have added the default call of ‘<?php ahp_recent_posts(5,30,20,”",”",7); ?>’ into sidebar.php of the template I am using. Then registered a new user, added a couple of posts – can see the actual posts but no Recent Posts lists as expected. Am I missing something? I’m stumped.

29 Chaslie 11.20.08 at 4:24 pm

Does anyone have any idea why this works for some and not others? Is it simply user error or is there a secret to install it and have it work? OK – we know where it needs to be installed correctly if in the sidebar, we know that posts have to be present (<30 days old) to show up in the plugin, we don\’t change the file name as downloaded and it can be placed in either /plugins/ or /mu-plugins/. Anything else?

Could it be \’permissions\’ (CHMOD) or the way it is uploaded (WS_FTP – auto)?

30 Chaslie 11.20.08 at 4:42 pm

Perhaps it doesn’t like WPMU 2.6.3? Could that be the problem? Does anyone have it working correctly with this version of WPMU?

31 face park 11.27.08 at 3:52 am

Hi, aziz

your plugin is so confusing. I use a simple tag you give
and all value of variable showing.

When I add to the code, the excerpt are missing.

I think it too depend on the css of the theme used.

32 Steven 11.28.08 at 3:23 pm

Its a much needed plugin, thank you! I would like to suggest adding thumbnail support, perhaps pulling the 1st image in the media gallery or custom fields, so that content has pics (more enticing!)

like this, but using your plugin would be fantastic:
http://nyherald.com

33 ovidiu 12.02.08 at 6:05 am

just tried the plugin, seems fine so far, but the gravatar link goes to: h**p://mainblog.com/article/author/sasha instead of to the right user blog, shoud say: user.mainblog.com/article/author/sasha and btw. article is the article name this widget is showing on, bot the original article? thats completely weird…

34 Satranc 12.12.08 at 6:34 am

Hi,
There is a modified version by me: http://abdullaharik.com/ahp-sitewide-recent-posts-for-wpmu-valid-xhtml/
Modifications: Turkish, Valid Xhtml.
You can see it at work: http://satranc.biz/

Thanks for great plugin.

35 David Johnson 12.23.08 at 9:17 pm

Works perfectly but is there anyway to have it pull another size Gravatar? The 24px is way to small.

36 iamzaks 12.26.08 at 8:14 am

Is there a way to be selective with the posts? for example, In my network there are 7 Blogs that deliver high quality news, and I want only those posts to be displayed. Is that possible?

37 Aziz Poonawalla 12.26.08 at 8:36 am

Hello everyone,

Thank you for your comments, suggestions, and for your requests. I apoloizse for being tardy on updating the plugin but I am preparing for some overseas travel shortly and will be back mid-January. I intend to release a new version with all the bug fixes above within a week or so of returning.

Quick answers –

David Johnson – you can edit the default pixel size for gravatars right in the code, theres a variable defined as $grav_size right near the top. I will see if theres an elegant way to allow you to specify gravatar size as a function argument, but this edit is a pretty easy one to make.

iamzaks – that is a harder change, because it involves modifying the SQL query. i think i know how to do that but i need to research it before giving you bad code. I will look at that after I get back.

ovidiu – you’re right thats a bug on my tofix list.

Steven – that really is beyond the scope of this plugin.

Chaslie – please use the latets version of the plugin – note that the default function call is much simpler now:

ahp_recent_posts(5, 30);

also, it doesnt matter what you call the plugin file, you need not rename it.

Jake, thats a heavily requested feature but it would require a major change to the sql query. its on y eventual feature list but as you can see there are a lot of smaller fixes that need to get nailed down first.

Thanks everyone for your feedback and I will attend to the plugin housekeeping when I get back.

38 Dave 12.31.08 at 2:43 am

One thing I don’t understand, is if I insert an image at the top of the post, when it is pulled to the main blog the text doesn’t show. Any idea why?

39 David Johnson 01.02.09 at 11:51 am

Thank you for the response, works beautifully! Quick question, where in the code can I block another post id? I want to block the main one, like it is now, and one other one. Is there a way to do that?

40 David Johnson 01.02.09 at 12:15 pm

Coming back to say that i got it to work. I know nothing about PHP but it looks pretty logical to me and a quick look through it I spotted the are where I needed to add the code. For anybody else that runs into the problem this what I did.

I found the place in the code, near the top that says:

// 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 blog_id != ‘1′ AND last_updated >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)ORDER BY last_updated DESC”);

I added “AND blog_id != ‘7′” without the quotes after the section that begins with delete = ‘0′ AND blog_id != ‘1′

Hope that makes sense! Enjoy

41 David Johnson 01.02.09 at 12:22 pm

oops! Just substitute 7 with the blog ID you DON’T want to shot up.

42 TTjip 01.21.09 at 5:05 pm

Where in the plugin can I change $how_many? And what format? like $how_many = 5? Sorry, not too familiar with php. Thanks

43 TTjip 01.21.09 at 6:07 pm

Oh, I think I understand. I need to put it in

44 Gary 01.21.09 at 6:32 pm

Have tried the plugin out. We have a setup where our wordpressmu install is on a subdirectory (/blogs) I have added the code, as mentioned in the comments within the plugin, to my sidebar.php: (ahp_recent_posts(5, 30);. I am running wordpressmu 2.65 using the Paalam theme. When the code is added nothing is added to the sidebar. I see other widgets but nothing is added relating to the plugin. Is there anything else I should try or is this due to the install being on a subdirectory?

45 TTjip 01.21.09 at 7:11 pm

Did you upload the plugin into the mu-plugins directory?

46 TTjip 01.21.09 at 7:20 pm

Questions: 1) The default 5, is that for $how_many?

2) Also, I notice right now I think all it does is one recent post per blog, how to change it so it shows the most recent posts regardless of which blog it is from?

47 Martin 02.13.09 at 7:45 am

I’m finding that the plugin isn’t stripping out all shortcode… in particular code used in the attachment/image uploader eg:[CAPTION ID="ATTACHMENT_698" ALIGN="ALIGNLEFT" WIDTH="300" CAPTION="CAPTION"][/CAPTION]

48 ton 02.20.09 at 12:06 pm

Hi!
I made it possible to show lists from fixed category, and also show not only one post but many posts which I want to show, and complete to make as my version.
Now, I can see 5 posts in ‘news’ category from each blogs, for example.

Thank you Aziz for your original works!
It’s really great works!!

49 vienna 02.22.09 at 8:57 pm

the plugin works great but i am having a slight problem…

the excerpts are not showing in WPMU 2.7…

is there any solution to this? please help.

50 vienna 02.22.09 at 8:58 pm

i tried AZIZ’s suggestion but the excerpts are still not showing.

any other work around to this?

51 iwantcandy 02.26.09 at 8:39 pm

Have you figured out how to display most recent posts, regardless of the owner?

So in other words, even if the last 5 were from the same blog, still list them all…..

This is much needed – thanks for any help.

52 Dan Gilmore 03.03.09 at 8:49 am

Aziz – Great plugin! I am using it for a wpmu installation at work, and it works great. I was wondering if you had a way to paginate the results, or if you were working on adding that functionality at all. My predecessor had a custom script that returned the 300 latest blog posts, but only showed 30 at a time on a page.

Keep up the awesome work.

53 Mio 03.08.09 at 5:54 am

Hi,

Is there a way to show the scrips outside the WPMU folder? How can I use the script on my mainpage (non WP page)?

Thanks guys!

54 Will 03.21.09 at 9:52 am

Great plugin – thanks for all your hardwork.

Unfortunately, i’m getting a slight error.

If I include blog name it includes and unwanted / for example: joe blogg/’s

I’ve tried edited the plugin but I cannot see what would be causing this. Any ideas anyone?

55 inson 03.25.09 at 9:07 am

please someone explain where exactly should I put this code?
Am I doing something wrong? below you can see the part of my home.php file

WordPress µ
This is a WordPress Mu powered site.

56 Nate 04.03.09 at 1:40 pm

Is it possible to limit the posts displayed to one blog and one category within that blog?

57 Tim 04.06.09 at 12:41 pm

I don’t see the enclosing in my widget in my theme. I would like ot be able to class that UL as well. What am I misising?

58 Tim 04.06.09 at 12:42 pm

Oops, post 57 should read “I don’t see the enclosing <ul> in my theme…”

59 Angelo Bertolli 04.08.09 at 11:27 am

Hey Aziz, can you contact me? I widgetized version 0.32 of this plugin a long time ago, and even added some of the changes you did. However, your version of the plugin looks much much nicer, and I would like to merge my code with yours: I would like to send you a widgetized version of your 0.61 that you can post as an update on wpmudev.org. If you’re not interested in continuing development, maybe you can add me to your wpmudev project or let me manage it. Otherwise, please let me know how to contact you so I can give you my code.

60 Kilmarac 04.13.09 at 5:08 am

Running into a slight problem.

Ive uploaded the entire folder to mu-plugins

Ive uploaded both files to mu-plugins

No matter how I do it, I keep getting this

ahp_recent_posts plugin is missing, the widget will not be enabled until the plugin is installed

So what did I do wrong.

61 satranç oyunu 05.09.09 at 2:02 pm

Thank you for plugin

62 Darren 05.18.09 at 1:56 pm

Here is some modded up SQL for including only specific blogs in the query.

Around line 13, just replace this line which excludes the main blog

delete = AND blog_id != ‘1′

With this

AND blog_id IN (’2′,’3′,’4′)

And use the Blog ID for the blogs you want to include, all others not listed will be left out of the plugin’s results.

Useful if you want to feature/drive traffic to certain blogs.

63 Darren 05.18.09 at 1:58 pm

Make that “around line 131″ in the above.

Also, in case it wasn’t clear, I’m talking about modifying the file “ahp_recent_posts” version 0.6.1, though it may work for others.

64 guidestobuy 05.24.09 at 11:10 am

Hello, is there possible to show image on every recent post rather than just an excerpt?
or maybe you can merge this plugin with advance excerpt plugin (http://wordpress.org/extend/plugins/advanced-excerpt/)

Thank you

65 Roman 06.10.09 at 1:41 am

Hi there,

thanks for this nice plugin. Would be possible to show recent posts only of specified blog ID? I mean show recent posts of e.g. blog ID 1 in sidebar and blog ID 2 in footer. Thanks.

66 Juan 06.26.09 at 8:47 am

Before anything, thank you very much for this great plugin!!

Now this is my problem:
I have a blog (id=28) that has many authors, but I would like to show a specific avatar in the excerpt instead of the authors avatar, so that it’s always the same image. (Actually the excerpts from that blog display each author’s avatar, that’s what I want to change).
Please help me!
Thank you very much for your time!

67 Mike 07.31.09 at 8:02 am

I’ve put your code on my site in three locations – not very pretty, but the basic code anyway.

But instead of any content from the blogs, even though it’s picking up the blogger and the blog address link correctly, the content itself is either the � symbol or a blank box. Clearly I’ve done something wrong. Any idea what?

68 fplus 08.17.09 at 10:18 am

hi!
Well, I put this code:

but text don’t go at the right side of the gravatar…
how could I do?
Thanks

69 fplus 08.18.09 at 1:07 am

why does code not appear?

70 Ray 08.26.09 at 9:19 pm

Hi Aziz,

I’m having a little bit of trouble with your plugin.

The posts are supposed to be sorted from latest to oldest; but I get a few that get misplaced in the order.

Also I’m not getting the latest post for one of the blogs; I’m getting the second one instead.

Any idea why?

71 Darrin Dickey 08.26.09 at 9:43 pm

I have the same issue with one of my blogs showing the second newest post instead of the most recent. Does anyone know why this happens or how to fix it?

72 Ray 08.26.09 at 9:46 pm

Okay I’ve looked into the matter.

For the “not getting the latest post” bug, in your $thispost SQL query… you should use ORDER BY $blogPostsTable.post_date instead of $blogPostsTable.ID.

Also about the weird, blog order bug I was experiencing… I guess $wpdb->blogs looks at the last updated activity in the admin area and not just posts.

But I guess there isn’t an easier way to quickly identify which blog has the latest post, right?

73 Darrin Dickey 08.26.09 at 10:45 pm

Ray,

I figured out the issue with the second newest post showing instead of the newest… on mine. The ID numbers had somehow gotten out of sync and the second newest post had a higher ID number than the newest post. The mySQL query in this plugin sorts by ID number. So the highest (in this case, the second newest post) ID number showed.

You can do one of two things to correct this. Go into PHPmyAdmin and renumber the IDs to have the newest post be the highest number. (Pain in the butt and runs the risk of having this happen again.)
Or change the mySQL query to order by post_date instead of ID.

I hope this helps you.

Now, if I could just figure out how to get more than one post per blog to show….

74 Ray 08.26.09 at 11:17 pm

Darrin,

I already listed the post_date solution in the comment right above yours.

Getting more than one post is easy; change “DESC limit 0,1″ to “DESC limit 0,x”. Where “x” is the number you want to show.

75 Darrin Dickey 08.26.09 at 11:43 pm

Ray,

Sorry I missed that.

I tried changing to “DESC limit 0,3″, but still just get one post from each blog. I know the mySQL query returns 3 results. I’ve tested it. I must be missing something else.

Darrin

76 Ray 08.27.09 at 12:03 am

Hey Darrin,

I thought changing the limit would allow you to have more posts from the same blog. But I didn’t check it out myself! hehe.

I get the problem now… Aziz hardcodes $thispost so only the first entry is outputted. eg. $thispost[0].

What you’d need to do is do a foreach loop after the if($thispost) conditional.

eg.

if(thispost) {
foreach($thispost as $thePost) {
...

Then change all remaining intances of $thispost[0] to $thePost. Make sure you close the foreach loop!

That should allow you to output more than one post per blog!

Let me know if that works!

77 Darrin Dickey 08.29.09 at 8:48 pm

Hmmm…. I had tried that before and it didn’t work. I changed it to:

foreach ($thispost as $thePost) :

… do stuff …

endforeach;

I got an error saying “Cannot use object of type stdClass as array…” Something about it pulling an object as result. I’m not highly proficient at PHP yet, so I haven’t worked out the fix for it.

Darrin

78 Aziz Poonawalla 09.03.09 at 5:14 am

Darrin, sorry for not replying sooner. Theres a backlog of issues I need to address. Rest assured I will be looking at this soon.

79 the starlit sky 09.06.09 at 5:19 am

great plug-in

but i can’t seem to install it properly :( :( :(

will it work in my wordpress 2.6 version?

80 Dean 09.29.09 at 8:30 am

As pointed out above, the first search gets each blog by the last update activity, which doesn’t necessarily equate to the most recent post.

I was wondering, could you take the query results for each blog and put them into an array, then sort that array based on the post date and output the values in that method? This way, it wouldn’t matter which blog was updated last, the newest post would be first.

I’m going to look into it myself and I will post back if I get it to work.

81 Dean 09.29.09 at 9:13 am

Okay, this is how you do it.

Get blog list
Create Array
Create Counter
Loop thru blogs
Get posts (change query to have post_date as first column)
use $wpdb->get_row($sql, ARRAY_A); where “$sql” is the post query
insert results into array

if($thispost) {

$postArray[$i] = $wpdb->get_row($sql, ARRAY_A);
$i++;
}

sort array
array_multisort($postArray, SORT_DESC);
loop through array as before to post the code

The only issue right now is the blog link, but I’ll probably figure that out soon and then I’ll post a complete example.

82 Dean 09.29.09 at 10:23 am

Okay, I posted my fix. Make sure that you notice that I changed the formatting of how the posts are displayed. This formatting might not work for your needs.

Sitewide Recent Posts – hack

83 Dean 09.29.09 at 2:45 pm

Okay, after finishing that little hack, I decided to do a little bit more.
I wanted to show more than one post per site, so I added the ability to set the limit per site. This doesn’t override the total number of posts seen, but it shows more per site. It still sorts them all by date.

I did a write up and posted the code.
AHP Sitewide Recent Posts – hack 2.0

84 Steve 10.22.09 at 8:46 am

This is a great plugin. What would I put in my CSS to change the font on this??

85 Adityo 10.24.09 at 12:04 am

HI,

what a good plugin, i have implemented it on my wpmu, but is there someone here who can tell me how to makes older post on the bottom of ahp plugin ? so there will be an older post link that show all of the older posting( like 1/2 day before ) . Any help or suggestion is appreciated :) thanks

86 Alexandria 10.26.09 at 1:02 pm

I figured out out to strip out wordpress’s caption shortcode and make sure that a excerpt is displayed when whitespace precedes the actual text in the excerpt.

Whitespace became an issue for me when stripping out html and captions from the beginning of the except because the first character encountered was a blank space, causing the script to think that there was no excerpt for a blog post.

Somewhere around line 242 insert a preg_replace to remove the caption shortcode and a trim() to remove the extra whitespace:

// get post content and truncate to (numwords) words
$thiscontent = strip_tags( $thispost[0]->post_content );
$thiscontent = preg_replace(”/\[caption.*\[\/caption\]/”, “”, $thiscontent);
$thiscontent = trim($thiscontent);
preg_match(”/([\S]+\s*){0,$exc_size}/”, $thiscontent, $regs);

Instead of:

// get post content and truncate to (numwords) words
$thiscontent = strip_tags( $thispost[0]->post_content );
preg_match(”/([\S]+\s*){0,$exc_size}/”, $thiscontent, $regs);

87 Mao 11.08.09 at 11:24 am

Thanks for this great plugin, but I didn’t make it work…
When I wanna active it, there’s an error:
Cannot redeclare ahp_recent_posts() in ../wp-content/plugins/1104069568_ahp_recent_posts_0.6.1.php on line 90
ya, it’s plugins, ‘coz when I put it in mu-plugins, the WPMU even can’t find it~
Please help me, thank you!

88 Mao 11.08.09 at 11:47 am

alright, it fixed.
I uploaded the php file both to plugins/ and mu-plugins/, then the function is defined twice….
sorry …

89 Dkean 11.12.09 at 1:36 am

Is there any code/ or adjustment to make this paginated? Would be awesome to have the ability to show more pages of results.

Anyone has done this before?

90 Mike 11.22.09 at 2:42 am

How can I get all the features ahp Recent post offers like: gravatar, date, author name,comment count, blog name, post name, post excerpt, excerpt capitalization to work on my regular Recent Post widgets. I don’t want it from all blogs just single blogs?

91 zoe 12.11.09 at 3:14 am

Hello, how the addition of plug-in page displays only one article?

92 zoe 12.11.09 at 4:45 am

Sorry, about only one article . I think I understand..Thank you.
en..
Will be able to add comments link do?

93 Dean 12.16.09 at 1:56 pm

I made another update to the code I modified.
I changed the display part so that the different parts of the display turn off based on the option code


AHP Sitewide Recent Posts – hack 2.2ish

94 Lana 01.16.10 at 8:59 am

Hi Aziz

I have had this plugin installed for awhile now and it was working fine. After a break from working on the site over Christmas, I have came back and found that no matter what I try in editing the arguments, the plugin will only list 1 recent post regardless of the number I list in the code. I am currently using the simplest code to show you what I mean with the latest version of wpmu . . .

Any thoughts or suggestions would be great.

95 Lana 01.16.10 at 9:01 am

oops . . . sorry . . .

96 Lana 01.16.10 at 2:53 pm

Please disregard my question. I figured it out by adding a new post to a different blog and it is now showing that post as well.

97 werner 01.25.10 at 3:30 am

Thanks for your great plugin – the only trouble I have: how can I disable the html-stripping. In the 0.6.1 version I can’t find the strip_tags …

thanks werner

98 Seeley 01.27.10 at 12:47 am

I have the exact same question as werner, how to disable the html stripping.

Thanks!!!

99 chris 02.08.10 at 2:58 pm

Really like the plugin a lot! I did change a few things.
Order of most recent blog post issue.
It sorts the list of site by when it was last updated on the master blogs table. Problem with this is a lot of my users update pages on their blogs and not posts as often. So it showed those sites as recently updated. I added some SQL to the query and sorted by Post Date of each blog to get the most recent posts.

Odd Coding showing in posts
Stripped out more of the wordpress only captions and such using php. Worked good for my site.

100 chris 02.08.10 at 3:01 pm

Look for strip_tags to get rid of the HTML stripping.

101 werner 02.10.10 at 6:48 am

@chris: sadly there is no strip_tags function in the version 0.6.1 …

102 Roman 02.11.10 at 8:19 am

Nice script, but for some reason on my page tekst is always on next line after avatar…

How to make this tekst showing next after avatar?? Same line with avatar, but on right side after avatar

Thank you!

103 Roman 03.01.10 at 3:48 pm

Hi!

We using this plugin in MU…

witch tables do we have to create for DB (how to change db-config.php) if we are using multi-db plugin???
Or we don’t need to make any changes???

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the answer to the math equation shown in the picture. Click on the picture to hear an audio file of the equation.
Click to hear an audio file of the anti-spam equation

Previous post: Who do you follow on twitter?

Next post: Please vote for my plugin