Random Front-Page WordPress

1

Greetings, I would like to know if any of you know how to do a front-page in a random way, that is:

I have 4 types of Home

Home 1 Home 2 Home 3 Home 4

By reloading the main page that can load any of these home randomly.

A thousand thanks.

    
asked by pio 29.08.2016 в 04:49
source

3 answers

2

From the previous code I managed to leave it more complete so that I did not look for another template (post / page):

      $rand = rand(1,4);
         if ($rand>=1&&$rand<=4){
                get_template_part( 'template-parts/content', 'perfil-'.$rand );
         }else {
          get_template_part( 'template-parts/content', 'none' );
      }
    
answered by 05.09.2016 / 17:58
source
3

In your template front-page.php you should do something like this:

$rand = rand(1,4);

switch($rand){

    case 1:
        get_template_part('template1');
    break;

    case 2:
        get_template_part('template2');
    break;

    case 3:
        get_template_part('template3');
    break;

    case 4:
        get_template_part('template4');
    break;

}
    
answered by 29.08.2016 в 12:24
2

Extending the above, you can use the function wp_list_pages , where you pass as a parameter that the post_status = ' publish '. That way you can only take out the published pages, or apply other filters by category, author, etc etc Once you have the list, you use sizeof to know the number of pages returned and with that you throw the random as parameter of upper limit, from 1 to X ..

    
answered by 26.05.2017 в 11:32