Widgets Reset on Refresh
-
Hi there, i need help regarding widgets.
I have sidebars and when i add text to them via Appearance>Widgets, its fine. But when i refresh that page, it resets the text for the sidebar to nothing.
This means i can add text and stuff to my custom sidebars once, but when i want to go back to edit a page, all of the sidebars would be reset.
Any ideas what might cause this?
I have a functions.php file and in it i create a seperate sidebar widget for every page and name each one according to the page name.
Thanks a lot for any help
-
Edit: Foregot to add the first 3 variables.
Here is the code in my functions.php page:
$pagecount = count(get_pages('parent=0')); $names = array(); $IDs = array(); function getNames() { $i = 0; $pages = get_pages(); foreach($pages as $page) { $name = $page->post_title; $names[$i] = $name; $id = $page->ID; $IDs[$i] = $id; if ( function_exists('register_sidebar')) { register_sidebar(array( 'name' => $names[$i], 'id' => $IDs[$i], 'description' => '', 'before_widget' => "<div class='left_mid'>", 'after_widget' => '</div>', 'before_title' => "<h2 class='cusstom'>", 'after_title' => '</h2>')); } $i++; } } getNames(); if (function_exists('register_sidebar')) { //create the default widget. If no text is entered in another widget, the default text will be displayed register_sidebar(array( 'name' => 'Default', 'id' => 'default', 'description' => 'The default text that should be displayed. Is overridden when text is entered in another widget for the page.', 'before_widget' => "<div class='left_mid'>", 'after_widget' => '</div>', 'before_title' => "<h2 class='cusstom'>", 'after_title' => '</h2>')); }
The “default sidebar doesnt reset when i refresh the page. All the others do. Why is that?
I found the solution.
I made the id the same as the name instead of IDs[$i].
I have no idea why this fixed the problem. Could anyone that has more knowledge please tell me why it didnt work with id = $IDs[$i]?
Thanks
- The topic ‘Widgets Reset on Refresh’ is closed to new replies.