Select Random Entries

Christian Santiago's Avatar

Christian Santiago

15 Sep, 2011 04:42 AM

I am working on a theme that requires I choose up to 300 random entries from all that exist in my blog, plus what I bring in from other blogs. Ideally, I could do this dynamically, as I want to avoid publishing a file that is large in size. Any plugins or strategies out there for achieving something like this?

  1. 1 Posted by Byrne Reese on 15 Sep, 2011 06:11 AM

    Byrne Reese's Avatar

    There is no plugin that I am aware of that performs this function as you describe. Can you explain in a little more detail what the user experience is like for what you are trying to build? What is special about 300? Are you displaying all of them, or a random sampling of 300 entries?

  2. 2 Posted by Dan Wolfgang on 15 Sep, 2011 12:11 PM

    Dan Wolfgang's Avatar

    Christian, check out https://github.com/rayners/movable-type-plugin-random-entries

    No documentation, unfortunately, but It looks like you would use it as:

    <mt:Entries random="1" lastn="300">
        <p><mt:EntryTitle></p>
    </mt:Entries>
    
  3. 3 Posted by Christian Santi... on 15 Sep, 2011 05:55 PM

    Christian Santiago's Avatar

    We want to display in our UI a random sampling of 300 of the 800-1000
    entries we have. We also want to display them at runtime. However,
    publishing a static file of 1000 XML elements means the client downloads a
    large file, and the view takes about 20 seconds to load when the document is
    not cached.

    That is essentially the problem I am trying to solve. I have some ideas,
    but am open to suggestions. More input is always good.

  4. 4 Posted by Byrne Reese on 16 Sep, 2011 06:33 PM

    Byrne Reese's Avatar

    The approach I might consider taking is to publish a file that builds an array in PHP of 300 random entries. At runtime, a simple loop could then pull 10 random entries from the array.

    PHP is read and parsed quickly so performance shouldn't be a problem. I would however avoid client side parsing of XML. Do it all server side.

  5. 5 Posted by Christian Santi... on 20 Sep, 2011 08:16 PM

    Christian Santiago's Avatar

    Byrne, I took your advice and created an index template that adds entries to an array in PHP. I use the array_rand function to get a random list of 300 keys, then access the values from the original array at run time. It works great, and returns results to the browser in about 2 seconds.

    Thanks!

  6. Christian Santiago closed this discussion on 20 Sep, 2011 08:23 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac