Multiple blog home demos in WordPress theme

wordpress
themeforest
#1

Hi,

I want to show multiple blog layouts without creating custom WP templates. I saw in many themes the URL is something like: theme.com?home_layout=grid&sidebar=left. I tried to Google it, but can’t find the right answer. So I guess it’s just a GET request and based on this request you switch layout and settings in Customizer.

So, this way I can have all the home demos inside of index.php with multiple layouts based on the URL condition. But when theme goes for sale I have to remove it from production file? How other authors achieve this?
Hope someone can help :slight_smile:

So here is the example of code:

<?php

          $layout = isset( $_GET['layout'] ) ? $_GET['layout'] : 'grid';
          $sidebar = isset( $_GET['sidebar'] ) ? $_GET['sidebar'] : 'right';

          switch ( $layout ) {

            case 'list':
              get_template_part( 'template-parts/content-list' );
              break;
          }

          switch ( $sidebar ) {

            case 'left':
              set_theme_mod( 'sidebar', 'left' );
              break;
          }

        ?>
How to make links like this?? Help
#2

Hi @DeoThemes,

You need to have 2 versions of theme, one for sale and one for showcase that will display layouts depending on url parameter.

Thanks,
Luca

1 Like
#3

So my code above is correct? It’s working but when I try to switch sidebar it only works after second reload. Here is the example:

<?php
          $sidebar = isset( $_GET['sidebar'] ) ? $_GET['sidebar'] : 'right';

          switch ( $sidebar ) {

            case 'left':
              set_theme_mod( 'sidebar_settings', 'left-sidebar' );
              break;

            default:
              set_theme_mod( 'sidebar_settings', 'right-sidebar' );
          }

        ?>
#4

I’m not sure, but the case may be that you set the theme mod after current theme settings are loaded, so new settings will be considered on another refresh.

Thanks,
Luca

2 Likes
#5

Ok, I fixed it :slight_smile: Thanks for the help.

1 Like