Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Autofocus+ Pro Theme | Randomize post image grid on homepage WordPress

  • SOLVED

Hello,

I currently have the Autofocus+ Pro theme installed on my website and have a question with the grid of images on the homepage:

daniel-marsden.com
Username: test
password: testes

I am wondering if there is an option to randomize the order in which the posts appear on the front page. Currently they appear top to bottom in the order they were created and I'm wondering if I can randomize this display so the same posts aren't always hidden at the bottom.

Also, can I rearrange the order of the sticky post header images? Currently there are 4 large header images at the top of the page that loop. These are arranged by the date they were created. Can I change the order of these and select which post/image I'd like to come first, second, etc.?

Any help would be appreciated.

Thank you!

Answers (3)

2011-05-12

Christianto answers:

Hi Daniel,

Please add this code on your functions.php

function fix_index($query) {
if ( $query->is_home ) {
$query->set('orderby', 'rand');
}
return $query;
}
add_filter('pre_get_posts', 'fix_index');

Please tell me the result..


Daniel Marsden comments:

Christianto,

This worked like a dream. Placed it near the top of my functions.php file and VIOLA!

Final question for you (the second part of my question above):

Can I rearrange the order of the sticky post header images? Currently there are 4 large header images at the top of the page that loop. These are arranged by the date they were created. Can I change the order of these and select which post/image I'd like to come first, second, etc.? I don't necessarily want these to appear in a random order - I'd like to have control over which one is first, second, third and fourth.

Thanks, you've been great help!


Daniel Marsden comments:

Christianto,

I just realized your code is doing something unexpectedly undesirable to my site.

When you click on a post such as for example:

http://www.daniel-marsden.com/?p=1689

the code is now randomizing the order of the large sliding gallery images at the top of the page instead of following their pre-assigned menu order.

I am attaching a screen shot to show that each image is assigned an order from 1-6 and by clicking refresh on the post page you'll see it shuffles the gallery images disregarding the menu order.

Any insight?

Thank you.