Widgets (entry valid for WordPress v2.2.2) – In this version are already integrated Widgets for the sidebar, we will look more closely at how to use them and we will describe how to correctly styles using CSS. The theme directory you have a file functions.php to open it, right from the start is the definition of what will happen before and after the widget, the widget title.

if ( function_exists('register_sidebar') ) register_sidebar(array('before_widget' => '<li id="%1$s" class="widget %2$s">','after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',

1) If you are ok with the fact that all elements of the sidebar will be styling a single definition, adjust the following settings and enter the definition of the class .bar to file style.css.

.bar {	padding: 5px 5px 5px 5px;
	background: url('images/bar.jpg') no-repeat;
	color: White;
  }
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<div class="bar">',
'after_widget' => '</div>', 'before_title' => '<h2>',
'after_title' => '</h2>',
));

Now check out folder /wp-includes/ and open file widgets.php and put above changes here too:

$defaults = array(
'name' => sprintf(__('Sidebar %d'), $i ),
'id' => "sidebar-$i",
'before_widget' => '<div class="bar">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
);

2) If you need some elements sidebar stylish different definitions, we have to reflect how these settings in the file widgets.php as individual files of the widget plugins. The following is an example of the various functions of the file widgets.php directly modify, add CSS class .bar

function wp_widget_meta($args) {
	extract($args);
	$options = get_option('widget_meta');
	$title = empty($options['title']) ? __('Meta') : $options['title'];
?>
<?php echo $before_widget; ?>
<div class="bar"><?php echo $before_title . $title . $after_title; ?>
<ul><?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo attribute_escape(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo attribute_escape(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
<li><a href="http://wordpress.org/" title="<?php echo attribute_escape(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>
<?php wp_meta(); ?>
</ul>
</div>
<?php echo $after_widget; ?>
<?php
}>

Similarly we do with external widgets, the only way we will be able, for example, Event Calendar to use a different class.

  /** Event Calendar widget. */
  function ec3_widget_cal($args)
  { extract($args);
    $options = get_option('ec3_widget_cal');
    echo '<div class="otherbar">';
    echo $before_widget . $before_title;
    echo ec3_default_string($options['title'],'Kalendář');
    echo $after_title;
    ec3_get_calendar();
    echo '</div>';
    echo $after_widget;
  }

David

Graphic and website designer, currently, I attend to the maintenance of about thirty sites for existing clients as well as creating websites for the new ones. In my free time, I get into the secrets of the world of Linux, SSH, WP-CLI and I’m preparing this blog.

More:

WordPress Evolution and Updates WordPress Evolution and Updates arranged in nice Infographic. As we all know WordPress is an Open source platform where many experts contribute and ma...
Search results duplicated if in more than one cate... WordPress › Support » Search results duplicated if in more than one category (2.1) - Question: With WP 2.1 a search will now repeat a post found thro...
Elegant Themes – Premium WordPress Club Elegant Themes is a WordPress theme club owned by Nick Roach with one goal in mind, provide elegant designs crafted WordPress themes with simplicity a...
The benefits of using WordPress development in e-c... Website is a major tool for any company or business today to portray its features to the potential customers. When a company or business prepares a we...
10+ Useful WordPress Code Snippets We have collected a useful list of 10+ WordPress Code Snippets that we believe you will find really useful especially if you develop sites like we do....

Newsletter

Join our mailing list to receive the latest news and updates.

You have Successfully Subscribed!

Pin It on Pinterest