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.
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.
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' );
}
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;
}
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 ..