When adding widgets, the CSS coding is lost.
-
Hey everyone.
I’ve got a blog that I host, and in the sidebar it has the following code:
<div class="Left"> <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar() ) : else : ?> <br /> <div class="BlockContent"> <h2><?php _e('Calendar'); ?></h2> <?php get_calendar(); ?> </div> <br /> <div class="BlockContent"> <?php wp_list_pages('depth=3&title_li=<h2>Pages</h2>'); ?> </div> <br /> <div class="BlockContent"> <h2><?php _e('Categories'); ?></h2> <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?> </div> <br /> <div class="BlockContent"> <h2><?php _e('Archives'); ?></h2> <?php wp_get_archives('type=monthly'); ?> </div> <br /> <div class="BlockContent"> <?php get_links_list(); ?> </div> <br /> <div class="BlockContent"> <h2><?php _e('Meta'); ?></h2> <?php wp_register(); ?> <?php wp_loginout(); ?> <?php wp_meta(); ?> </div> <?php endif; ?> </div>Now, in that code you’ll notice the Calendar, Pages, Categories, Archives, Links and Meta are all in the BlockContent div style.
This is the style for that class:
.Left .BlockContent { background: #fff; border: 1px solid #dedac3; padding: 10px; }Here’s the issue, whenever I go into the admin section of the blog and add a widget on the sidebar (even adding just the ones that are there already) the formatting disappears and looking at the code, the “BlockContent” divs are replaced with calendar-3 pages-3, categories-3, archives-3, and linkcat-2.
How do make it so when I add a widget, it retains the formatting of the “BlockContent”
-
read ‘register sidebar’
http://codex.ww.wp.xz.cn/Function_Reference/register_sidebarThanks so much for replying.
Looking over the page I’m seeing two things.
One, this line of code:
<?php register_sidebar( $args ); ?>Am I putting that in my sidebar.php?
Also, next on my to-do list is to add a second sidebar to the right side of my blog (current theme has a sidebar only on the left), do I need to change the code to account for that?
Second it the default values:
<?php $args = array( 'name' => sprintf(__('Sidebar %d'), $i ), 'id' => 'sidebar-$i', 'description' => '', 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' ); ?>I’m guessing this is where I’m distinctive about the setting, etc.
Where do I put this code, and how would I integrate the CSS from my first post into it?
Thanks so much!
Sorry I’m not really clear on how to do it.
Doing some more reading online, do I put that code in the functions.php?
I’m noticing the code is in PHP.
How do I use this to make sure any added widgets use a certain CSS class?
do I put that code in the functions.php
Yes
How do I use this to make sure any added widgets use a certain CSS class?
Add your class to the list in this line:
'before_widget' => '<li id="%1$s" class="widget %2$s">',So I would copy and paste this into my functions.php?
<?php $args = array( 'name' => sprintf(__('Sidebar %d'), $i ), 'id' => 'sidebar-$i', 'description' => '', 'before_widget' => '<li id="%1$s" class="BlockContent %2$s">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' ); ?>Right now this is all my functions.php has in it, what do I replace and/or where should I paste the code?
<?php if ( function_exists('register_sidebar') ) register_sidebar(); ?>…and that’s it? That’s all I’d need to do?
Try:
<?php $args = array( 'name' => sprintf(__('Sidebar %d'), $i ), 'id' => 'sidebar-$i', 'description' => '', 'before_widget' => '<li id="%1$s" class="BlockContent %2$s">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' ); if ( function_exists('register_sidebar') ) register_sidebar($args); ?>Hmm, I did that, but now when I add a widget in the admin area, it doesn’t change on the page.
Did I need to put
<?php register_sidebar( $args ); ?>somewhere?The link to the page is dev.hesedbooksandgifts.com
Have you created another sidebar template file?
Yea, I’m going to be adding a second sidebar to the site once I figure out the widgets issue.
The filename is sidebar-right.php. Here’s it’s code (I think it’s just a copy of sidebar.php):
<div class="Left"> <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar2() ) : else : ?> <br /> <div class="BlockContent"> <h2><?php _e('Calendar'); ?></h2> <?php get_calendar(); ?> </div> <br /> <div class="BlockContent"> <?php wp_list_pages('depth=3&title_li=<h2>Pages</h2>'); ?> </div> <br /> <div class="BlockContent"> <h2><?php _e('Categories'); ?></h2> <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?> </div> <br /> <div class="BlockContent"> <h2><?php _e('Archives'); ?></h2> <?php wp_get_archives('type=monthly'); ?> </div> <br /> <div class="BlockContent"> <?php get_links_list(); ?> </div> <br /> <div class="BlockContent"> <h2><?php _e('Meta'); ?></h2> <?php wp_register(); ?> <?php wp_loginout(); ?> <?php wp_meta(); ?> </div> <?php endif; ?> </div>Try using:
<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar('2') ) : else : ?>
The topic ‘When adding widgets, the CSS coding is lost.’ is closed to new replies.