WordPress.org

Ready to get started?Download WordPress

Forums

Widget Displaying but not saving (3 posts)

  1. ServerStorm
    Member
    Posted 2 years ago #

    Hi,

    I am new to developing themes and have run into a snag which I am not sure how to troubleshoot or fix.

    In my functions.php I have put:

    function quickchic_widgets_init() {
    
    	register_sidebar(array(
    	'name'          => sprintf(__('A_%d'), $i )
    	,'id'   => 'widget_$i'
    	,'before_widget' => ''
    	,'after_widget'  => ''
    	));
    }
    
    add_action( 'init', 'quickchic_widgets_init' );

    In my header.php I have the following snippet of code:

    <div id='header_background'>
    	<?php dynamic_sidebar( 'A_0' ); ?>
    	<?php dynamic_sidebar( 'A_1' ); ?>
    </div>

    When I am in the Widgets Admin I can drag any plugins to either 'A_0' or 'A_1'. Say I drag the Text plugin to 'A_0', it displays, I type:

    <em class='header_img'></em>
    <em class='logo'></em>

    I then save. I then go to the user site and it shows that this has been pushed over. However if I refresh the Widgets Admin page then the text widget is gone, and the A_0 widget still shows.

    It is like it is always setting it to a new instance and not saving existing instances?

    I tested this with other widgets including Calander, Enhanced Text, and Links - all with the same result.

    Can you point me in the right direction.

    Steve

  2. ServerStorm
    Member
    Posted 2 years ago #

    Interestly, If I enable assessibility mode then I assign a plugin to the a_0 widget then save. It does retain the instance even with refreshing the Widget Admin; however there is not way to edit what was originally set.

    Yes I did rename the widget to a_? as I read a google thread on capital names of widgets causing problems in version 3; I am using version 3.2.1

    This is true even shutting off assessibility mode the assigned plugin does not show as associated with the a_0 widget, and there is not a way to edit it in assessibility mode; just add and inactive functionality is available.

  3. ServerStorm
    Member
    Posted 2 years ago #

    Hi,

    I got this working but I needed to make a small change.

    Here is my function.php code for the widget:

    function quickchic_widgets_init() {
    
    /*	register_sidebar(array(
    	'name'=> sprintf(__('a_%d'), $i )
    	,'id'   => 'widget_$i'
    	,'before_widget' => '<div id="%1$s" class="widget %2$s">'
    	,'after_widget'  => '</div>'
    	,'before_title' => ''
    	,'after_title' => ''
    	));*/
    
    	register_sidebar( array(
    		'name' => __( 'Top Left', 'ciia' ),
    		'id' => 'sidebar-1',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
    		'after_widget' => "</div>",
    		'before_title' => '',
    		'after_title' => '',
    	) );
    }

    You can see the new register_sidebar() 'Top Left' and you can see the more generic function of register_sidebar() sprintf(__('a_%d'), $i ) that I have commented out.

    Then in header.php the relevant widget code is:

    <?php dynamic_sidebar( 'Top Left' ); ?>

    Now when I add plugins to this widget it works; it saves.

    I believe this was a problem with generic function that I had.

    Hope this helps.

    Steve

Topic Closed

This topic has been closed to new replies.

About this Topic