I am trying to pick a video at random for playing on the homepage
I have not found any slider software to help me do this, but I am very close to finding a way using Views in combination with the Quode Slider which comes packed with the Bridge Theme.
Quote organises its slides using 'Sliders' as the taxonomy with member 'Slides' as the custom post type.
This site needs to play a full screen video on the homepage. It should select one from a choice of three or four at random. So visitors may see a different one when they return to the site.
I am therefore creating a series of Sliders containing a single video slide in each one. (The video slide is really a list of urls from AWS-hosted mp4, ogv and webm files which render the video).
Normally a slider is entered on a page in the Bridge theme by copying and pasting the full slider shortcode into a theme-generated custom field on the page. I have discovered that by writing a View to query the Slider Taxonomies, I can render the short code so it contains the 'slider' name like this - and it is this which renders on the page after I place the View shortcode, instead of the Slider shortcode, in the Slider custom field on the page:
<wpv-loop>
[qode_slider slider='[wpv-taxonomy-title]' auto_start='true' animation_type='slide' slide_animation='6000' height='' responsive_height='yes' anchor='top']
</wpv-loop>
My theory is that by restricting the views output to 1 item and by sorting it randomly, we can then pluck a slide (video) at random for display on the homepage each time it is loaded.
However, I can not find a way to sort the View - when it queries Taxonomies - randomly.
I have the option to sort the results by TermID, TermSlug, TermName, PostCount, TermGroup and NoOrder. I have tried No Order but it still outputs the same slider every time.
Can you suggest how to complete the final part of this puzzle?
Many thanks
Tim
Dear Tim,
Views is using wordpress function get_terms() to query terms of custom taxonomy, see the document:
http://codex.wordpress.org/Function_Reference/get_terms
Possible Arguments
orderby
(string)
id
count
name - Default
slug
term_group - Not fully implemented (avoid using)
none
There isn't such an "random" option. I suggest you try this:
1) Create a view to query all terms of possible terms
2) use Views filter hook wpv_filter_taxonomy_post_query to pick only one random item and output it:
wpv_filter_taxonomy_post_query
When displaying a View listing taxonomy terms, this filter is applied to the arguments that will be passed to the get_terms() call.
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_taxonomy_post_query/