How to get different homepage layout, based on the URL and customizer
Question
Not sure If my question is clear enough. I want to show different layout of the index.php, based on the URL and customizer settings. I see this format in some themes:
demo.website.com/theme/?home_layout=standard
For me it looks like it's a GET request, and based on this request different layout is loaded.
For example, I want to set layout to masonry in customizer and it should change the look of the homepage and the URL should be
demo.website.com/theme/?home_layout=masonry
If I switch to standard layout in customizer then I get this URL
demo.website.com/theme/?home_layout=standard
How to achieve this?
Solution
For those who wants to achieve the same, here is the answer: First we declare a variable with a simple condition to hold our GET request, if the value is not set than we define default value.
$layout = isset( $_GET['home_layout'] ) ? $_GET['home_layout'] : 'standard';
Then simply check the condition and load the template you want.
if ( $layout == 'grid' ) {
get_template_part( 'template-parts/standard-layout' );
}