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

Tags » , «

Autor: Texthelden
Datum: Sonntag, 14. Januar 2007 22:17
Trackback: Trackback-URL Themengebiet: Wordpress

Artikel merken: Empfehlen, bookmarken oder abonnieren

Feed zum Beitrag: RSS 2.0 Diesen Artikel kommentieren

22 Kommentare

  1. 1

    Where to insert the string get_random_posts(’’,’’,3) ?
    In the blog template or in each post?
    Tks
    Marco

  2. 2

    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 ;-)

  3. 3

    Kann man das auch auf Deutsch lesen ?
    lann leider sehr sehr Schlecht Englisch.

    Danke im voraus Vitali

  4. 4

    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.

  5. 5

    Any chance of a sidebar-widget version?

  6. 6

    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.

  7. 7

    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).

  8. 8

    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…

  9. 9

    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.

  10. 10

    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.

  11. 11

    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

  12. 12

    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.

  13. 13

    still have a problem.

    in IE it shows this error:
    Parse error: parse error, unexpected ‘

  14. 14

    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.

  15. 15

    I will drop you an e-mail.

  16. 16

    This is great, thanks. I have a lot of future posts, anyway to have it pull active posts only?
    Thanks.

  17. 17

    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 .

  18. 18

    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.

  19. 19

    […] WordPress Plugin Get Random Posts from Database […]

  20. 20

    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?

  21. 21

    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.

  22. 22

    […] 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.. […]

Kommentar abgeben