0

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=grid&sidebar=left
  • theme.com?home_layout=list&sidebar=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

  • what does it mean "but didn't work"? software always does something if it runs the code, or it do not run the code at all. Edit and describe what does happen and what have you done to debug. – Mark Kaplun Apr 9 '18 at 2:29
  • Hello Mark, for example when I put the sidebar at the left (theme.com/?sidebar=left) nothing happen, sidebar still by default at the right – Salahrd Apr 9 '18 at 3:00
  • so maybe the problem is with your front end generation part of the code? – Mark Kaplun Apr 9 '18 at 3:01
  • How to fix it? can you please help me – Salahrd Apr 9 '18 at 3:02
  • DId you notice you are passing the variable "sidebar" in URL but you are checking for "sidebar_position" in your function. – Robert hue Apr 9 '18 at 3:49
0

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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.