WordPress PlugIn Get Random Posts from Database
We’ve made a smal PlugIn for WordPress. It’s pretty simple. It just retrieves a bunch of random links to your posts in the WordPress database.
Installation
Simply unzip the get-random-posts.zip and copy the get-random-posts.php file into your ./wp-content/plugins directory.
Login to the WordPress Admin Interface and enable the PlugIn in the PlugIn section. That’s it.
Usage
Example: get_random_posts('’,'’,3); will return 3 random links to your posts. The post title will be used to display the link.
First parameter gives leading string for the string to return (default “li” in <>)
Second paramter gives trailing string for the string to return (default “/li” in <>)
Third paramter defines how much links you wish to receive (default 5)
That’s all about it. Have fun!
Download Get Random Posts V0.1





Montag, 15. Januar 2007 14:02
Where to insert the string get_random_posts(’’,’’,3) ?
In the blog template or in each post?
Tks
Marco
Montag, 15. Januar 2007 14:35
You must insert something like < +?php echo get_random_posts('<+li+>‘,’< +/li+>‘,3); ?+> in your template file.
For example: we use it in sidebar.php as you can see here on the right (Zufällige Auswahl -> Random Selection). Just take a look on the source of this html page here to see what you will receive with the statement above. Please note that you have to remove the ‘+’ signs, which i used here to escape parsing in the comment ;-)
Montag, 15. Januar 2007 22:20
Kann man das auch auf Deutsch lesen ?
lann leider sehr sehr Schlecht Englisch.
Danke im voraus Vitali
Dienstag, 16. Januar 2007 7:23
Im Prinzip musst Du lediglich die php Datei aus dem Zip File in den PlugIns Folder von WordPress kopieren. Danach aktivierst Du das PlugIn im Admin Bereich von WordPress. Fertig.
Im Template wo die zufälligen, verlinkten Artikeltitel zu sehen sein sollen packst Du dann den Code aus Kommentar 2 rein. In dem Beispiel wurde das in das sidebar.php geschrieben, da ich die Anzeige in der Einzelview auf der Sidebar haben möchte (siehe diese Seite hier). Hoffe das hilft Dir weiter.
Ich habe das bewusst auf Englisch gehalten, da das WP PlugIn Repository auch englischsprachig ist.
Mittwoch, 17. Januar 2007 0:52
Any chance of a sidebar-widget version?
Mittwoch, 17. Januar 2007 2:04
This resembles Malyfred of Skriker’s Archivist WordPress Plugin, which I wrote about recently. Do you know what the difference, good or bad, is between your two plugins? That will help people choose between the two.
Mittwoch, 17. Januar 2007 7:24
Hi Lorelle,
i didn’t know this PlugIn but the targets of the Archivist PlugIn differs. Archivist helps to retrieve and display one ore more older articles on the main article page. GetRandomPosts just retrieves some links to one or more articles and places them in the sidebar of the single view (where it makes the most sense from our point of view).
Mittwoch, 17. Januar 2007 7:27
Hi Juice,
we don’t use widgets until now. We wrote this just to satisfy our needs ;). I think it’s not so hard to convert it to a widget. But it’s not planned. I suppose you need only the some kind “widget container code” and put it all together…
Mittwoch, 17. Januar 2007 8:55
Thanks for the clarification. Yours displays random post excerpts in the sidebar, and Archivist sticks to random posts on the front page. That means people could use both. ;)
Great combination.
Mittwoch, 17. Januar 2007 9:15
Right, but to be more specific ;): Our PlugIn display only the title of a post as a link. No text or excerpt will/can be shown.
Freitag, 26. Januar 2007 20:12
hi there,
I tried to install the plug in but it couldn’t work. the error was:
“Parse error: parse error, unexpected T_STRING in”
I downloaded it, activated it, and put
‘,’‘,5); ?> in my sidebar
Samstag, 27. Januar 2007 10:42
Hi Mel, this should normally work without hassle. Please doublecheck that you used this code: < ?php echo get_random_posts('LI','/LI',3); ?> Put <> around the LI and avoid the space char before the “?php”. Check if the plugin is installed correctly in the plugins section of wordpress.
Montag, 29. Januar 2007 14:23
still have a problem.
in IE it shows this error:
Parse error: parse error, unexpected ‘
Montag, 29. Januar 2007 14:25
felix, if you could, email me … the codes and error messages is not shown on your blog comments and i could email them to you. thanks. if you want i’ll pay you to fix it on my blog. i am using WP 2.0.7. thanks.
Montag, 29. Januar 2007 14:52
I will drop you an e-mail.
Freitag, 16. Februar 2007 5:01
This is great, thanks. I have a lot of future posts, anyway to have it pull active posts only?
Thanks.
Freitag, 16. Februar 2007 11:22
Hm. Sound like a good idea. Maybe in a new version. There’s nothing planned at the moment, but maybe we need also such a feature in a few months :-) I think a parameter like “only posts not older then X weeks” would do the job. I will think about it .
Dienstag, 17. April 2007 19:20
hi, thanks for the great plugin - works for me just fine.
however, it also get pages, not just the posts. is there anyway that i cna change it so it only get back posts?
it would be great if you could get back to me on this one.
Samstag, 21. April 2007 1:49
[…] WordPress Plugin Get Random Posts from Database […]
Samstag, 28. April 2007 13:50
Hi thanks for the great code, i’m using it on my site.
But i noticed that its also pulling my pages. Is there any way to exclude them?
Samstag, 28. April 2007 16:51
Since v2.1 the internal handling / storage of pages changed in wordpress. We hav to make a smal modification to the code. I will do this in the next few days… stay tuned.
Freitag, 21. März 2008 6:25
[…] Wordpress Random Post Plugin Add This plugin is modified plugin where this plugin is based on get-random-post V 0.1. I modify this plugin because when iam use this plugin, all post is randomly great but sadly i saw my “page” post came up too.. Because i just want to show my random post only, so i made this change.. […]