As alluded to last week, some expansions have come to the SPLOTbox media collector theme for WordPress.
It made sense to add support for image-type media, making the SPLOTbox perhaps a bit broader than TRU Collector. This was relatively easy, so a SPLOTbox site can accept uploads of images (JPG, PNG, GIF), or add them by direct link to a URL, but also through autoembed of flickr.
And built in support is baked in for MixCloud (audio), Giphy (you know what they offer, right?), plus Slideshare and Speakerdeck (presentations).
All of these are in play, and you can see examples on the demo site at http://splot.ca/box
And this all works if you want a Big Box of All Kinds of Media. But I thought there might be use cases where a site should just accept certain types of media, say for curating videos, or maybe just audio.
So as of now (or 30 minutes ago), the theme options includes checkboxes to designate the media sites that are supported via URL:

These are then reflected on the front end share form as the list of sites supported (and if URLs for unsupported ones are entered, you see an error message).

If you update a site, there is a small chance on first load none will be checked, I’ve yet to isolate the use cases where this happens. This just means you have to check the ones you want to enable.
There also have been simplications on many of the SPLOTs to reduce the reliance on code in page templates for generating a link to a random item. I was able to pull that out into the general code (this is part of a secret SPLOT project I will hint at below) (that’s for any human that might be reading this) (hi human).
What I had done on many of my themes is to have a WordPress page template named page-random.php
that was merely code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// set arguments for WP_Query on published posts to get 1 at random $args = array( 'post_type' => $ptype, 'post_status' => 'publish', 'posts_per_page' => 1, 'orderby' => 'rand' ); // It's time! Go someplace random $my_random_post = new WP_Query ( $args ); while ( $my_random_post->have_posts () ) { $my_random_post->the_post (); // redirect to the random post wp_redirect ( get_permalink () ); exit; } |
This means to generate a URL for random content at a site located at http://somesite.fuzzy/
, a Page is created with a URL slug of random and then http://somesite.fuzzy/random
does the redirect work.
But this is all done in theme code now! Magic? Nah. The first part is registering a query parameter that the site can accept, like ?random=1
1 2 3 4 5 6 7 |
// ----- add allowable url parameters add_filter('query_vars', 'splotbox_queryvars' ); function splotbox_queryvars( $qvars ) { $qvars[] = 'random'; // flag for random generator return $qvars; } |
Then we need to add a rewrite rule for /random to be picked in a URL:
1 2 3 4 5 6 7 |
// ----- rewrite rules for licensed pretty urls add_action('init', 'splotbox_rewrite_rules', 10, 0); function splotbox_rewrite_rules() { // let's go random add_rewrite_rule('random/?$', 'index.php?random=1', 'top'); } |
And now we can handle the logic that was in the template in the theme functions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
add_action('template_redirect','splotbox_random_template'); function splotbox_random_template() { if ( get_query_var('random') == 1 ) { // set arguments for WP_Query on published posts to get 1 at random $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 1, 'orderby' => 'rand' ); // It's time! Go someplace random $my_random_post = new WP_Query ( $args ); while ( $my_random_post->have_posts () ) { $my_random_post->the_post (); // redirect to the random post wp_redirect ( get_permalink () ); exit; } } } |
Why is this a big deal? Well it’s not. But I am working through what might be a major leap for SPLOTkind… it means pulling all of the functionality out of a theme template… and into a yet to be fully fleshed out plugin. It means a major amount of re-coding the SPLOT logic, but if it works, it could mean the SPLOT functionality could be independent of theme.
That’s a lot of maybes for now, but so far the work is progressing well.
This new version of SPLOTbox is been tested on a few of my sites, but I could certainly stand for anyone out there to give it a go on your own site – get the latest version at https://github.com/cogdog/splotbox
Maybe you will see colored muffin tins.
Featured Image: Modified by adding SPLOTbox theme image to Muffin Tin Monday – Sweets & Treats lunch flickr photo by anotherlunch.com shared under a Creative Commons (BY) license
