Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #400210

    HI,

    I want to have a second sidebar Pages widget, so I can add another menu to certain pages.
    I now have three menus, one on top and one in use for the ‘food’ page.
    I want another menu driving the ‘wine’ page, so I need another Sidebar Page widget to choose in the page options.

    What I now did is added one in the register-widget-area.php file, and that works as expected.
    Add additional menu to second Page widget, open a page, set a sidebar, select second new widget for sidebar,and presto!

    But I rather not change the theme files, and would like to add this in my child theme. How can I ‘transport’ the code for the Sidebar Page widget (line 29-38) to the child theme, so it won’t break after a Enfold update.

    cheers!

    rob

    #400878

    Hey RobWu!

    What is the code you used?

    Regards,
    Elliott

    #400910

    Hi Elliot,

    What I did is copy the original code back into the php file, but renamed the widget. Very basic, but working. So now I have:

    foreach ($sidebars_to_show as $sidebar)
    {
    register_sidebar(array(
    ‘name’ => ‘Sidebar Pages’,
    ‘before_widget’ => ‘<section id=”%1$s” class=”widget clearfix %2$s”>’,
    ‘after_widget’ => ‘<span class=”seperator extralight-border”></span></section>’,
    ‘before_title’ => ‘<h3 class=”widgettitle”>’,
    ‘after_title’ => ‘</h3>’,
    ));
    }

    foreach ($sidebars_to_show as $sidebar)
    {
    register_sidebar(array(
    ‘name’ => ‘Sidebar Pages2’,
    ‘before_widget’ => ‘<section id=”%1$s” class=”widget clearfix %2$s”>’,
    ‘after_widget’ => ‘<span class=”seperator extralight-border”></span></section>’,
    ‘before_title’ => ‘<h3 class=”widgettitle”>’,
    ‘after_title’ => ‘</h3>’,
    ));
    }

    As I said, I feel better to have the second widget bar into my child theme.

    rob

    #401364

    Hey!

    If I am not mistaken, you can just add it directly to the child theme’s functions.php:

    
    		register_sidebar(array(
    			'name' => 'Sidebar Blog 2',
    			'before_widget' => '<section id="%1$s" class="widget clearfix %2$s">', 
    		'after_widget' => '<span class="seperator extralight-border"></span></section>', 
    		'before_title' => '<h3 class="widgettitle">', 
    		'after_title' => '</h3>', 
    		));
    	

    Best regards,
    Ismael

    #401378

    Hi Ismael,

    Thanks for the reply, but if I move the additional code to my child theme’s functions.php it doesn’t work.
    I’ll loose the second widget in the WordPress Widget section.

    The addition of the code to the functions.php doesn’t break the php, so there’s some small thing not working I guess.

    rob

    #401872

    Hi!

    I tested this code on functions.php and it adds the custom widget area called Sidebar Blog 2. If you’re worried about losing the existing widgets, rename the widget area then transfer the widgets to the newly created sidebar.

    Regards,
    Ismael

    #401944

    Hi Ismael,

    I did some testing. For starters, I emptied my child theme’s functions.php file and added just the code above. No second widget in WP.

    Than I turned off all plugins but the basic Woocommerce, and I get the following error on the top of the site:
    ‘Warning: Invalid argument supplied for foreach() in V:\xampp\htdocs\cavador\cavabin\wp-content\themes\enfold-child\functions.php on line 10″

    Line 10 here is: foreach ($sidebars_to_show as $sidebar)

    so that first line of code is rejected by the child theme.

    So close… ;-)

    rob

    #403291

    Any thoughts??

    I cannot get it to work for the site. Even with all plugins deactivated and an empty functions.php in the child theme.
    The php doesn’t break and the site works, but I don’t get another widget on the widget page.
    I do when I add the same code in the theme itself as described above.

    So I hereby want to request a second Sidebar Pages for the next update. I cannot be the only one who wants this.
    I feel very uncomfortable changing code in the theme itself, due to future updates and breaking functionality.
    Child themes are perfect for these reasons, and give you a more logical overview of what has been added or changed.

    rob

    #403296

    Hi!

    Replace it with this:

    register_sidebar(array(
    	'name' => 'Sidebar Blog 2',
    	'before_widget' => '<section id="%1$s" class="widget clearfix %2$s">', 
    'after_widget' => '<span class="seperator extralight-border"></span></section>', 
    'before_title' => '<h3 class="widgettitle">', 
    'after_title' => '</h3>', 
    ));
    
    register_sidebar(array(
    	'name' => 'Awesome Sidebar',
    	'before_widget' => '<section id="%1$s" class="widget clearfix %2$s">', 
    'after_widget' => '<span class="seperator extralight-border"></span></section>', 
    'before_title' => '<h3 class="widgettitle">', 
    'after_title' => '</h3>', 
    ));

    Regards,
    Ismael

    #403304

    Looking at the code I cannot see any differences, but for some reason this now works! For both widget additions.
    No idea who/why/what… ;-)

    I did make an official request for at least one additional Sidebar Widget on the forum, I hope it will emerge some day.

    Thanks for all the help, much appreciated!!

    rob

    #403821

    Hey Rob!

    Glad you got it fixed :)

    Best regards,
    Rikard

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Second Sidebar Pages Question – moving code to child theme’ is closed to new replies.