Show multiple option in URL with Redux framework in front end

I'm creating a WordPress theme in which I'm using the Redux Framework for creating the theme's options page.

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=gridsidebar=left
  • theme.com?home_layout=listsidebar=none

Now in the theme-option file i've got this one for the sidebar:

array(
'id'       = 'sidebar_position',
'type'     = 'select',
'title'    = esc_html__( 'Blog sidebar', 'omio' ),
'options'  = array(
    'left' = esc_html__('Left', 'omio'),
    'right' = esc_html__('Right', 'omio'),
    'disable' = esc_html__('Disable', 'omio'),
),
'default'  = 'right' ),

Now in the functions.php i've made a GET request code but didn't work.

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

switch ( $sidebar ) {

case 'left':
set_theme_mod( 'sidebar_position', 'left' );
break;

case 'disable':
set_theme_mod( 'sidebar_position', 'disable' );
break;

default:
set_theme_mod( 'sidebar_position', 'right' ); }

How to do it, please :) for example when I put the sidebar at the left (theme.com/?sidebar=left) nothing happen, sidebar stay by default at the right

Topic theme-options framework Wordpress

Category Web


You also wrong pass parameter $_GET method

$_GET method get parameter value in Url

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

switch ( $sidebar ) {

 case 'left':
 set_theme_mod( 'sidebar_position', 'left' );
 break;


  case 'disable':
  set_theme_mod( 'sidebar_position', 'disable' );
  break;

 default:
 set_theme_mod( 'sidebar_position', 
  'right' );
 }

try to use this:

function tes_sidebar() {
    global $redux_demo;
    $sidebar =& $redux_demo['sidebar_position'] ) ? $redux_demo['sidebar_position'] : 'right';
    switch ( $sidebar ) {
        case 'left':
        get_template_part( 'sidebar','left' );
        break;
        case 'disable':
        get_template_part( '' );
        break;
        default:
        get_template_part( 'sidebar','right' );
        break;
    }
}

call with this function: tes_sidebar();

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.