List posts in random order
-
Hello! On a website I am an administrator for, I have a list of all the posts on my front page and also a category with all the same posts. I want to randomize the order of the posts in the category section. So the front page is a list of them all but when they click on the category in the menu is becomes a new list of pots. Searched and searched for a plugin with no luck. Any way I can do this? Please talk to me like I’m five, I am still generally new at this.
THANKS!
website is http://www.runitbare.com if you wanted to look and see what I meant
-
these two codex have useful info:
http://codex.wordpress.org/Function_Reference/wp_rand
http://codex.wordpress.org/Function_Reference/get_categories
also, this codex: http://codex.wordpress.org/Template_Tags/get_posts
I have no idea what I am suppose to do with those.
Hello,
If you are comfortable adding a little code into your theme the following code will make all category listing pages random:
function set_category_listings_random( $query ) { if( !is_admin() && $query->is_main_query() && is_category() ) { $query->set( 'orderby', 'rand' ); } } add_action( 'pre_get_posts', 'set_category_listings_random' );Each WordPress theme folder will have a file called functions.php inside of it. Make a copy of this file somewhere else in case something breaks and open the functions.php file with a text editor. Go to the bottom of the functions.php file and add the code above. Save and upload to your site.
You could also add this code through the theme editor in the WordPress admin screen. Just make sure to make a backup in case something goes wrong!
Good Luck!
I found something else. Thanks though.
Custom Category Post Order pluginAlso do not have access to those files or an editor to edit them.
The topic ‘List posts in random order’ is closed to new replies.