Anyway, a few weeks ago I was asked to create a wordpress theme with widgets all over, left, right, bottom, and top. Searching through the wordpress codex documentation and in some other blogs, I came across about registering a sidebar. Now how do you do that? after several hours of searching and experimenting how things work I found that you need to register it under the functions.php file of your theme.Here is a sample of it:
I guess it is pretty straightforward, and I don't think I need to explain the before and after thing, to know more about sidebars you could check this link out.if ( function_exists('register_sidebar') )
register_sidebar(array(
'name'=>'sidebar1',
'before_widget' => '<li id="%1$s" class="widget"><div class="widget-top"></div><div class="widget-content">',
'after_widget' => '</div></li>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
));
register_sidebar(array('name'=>'sidebar2',
));
register_sidebar(array('name'=>'sidebar3',
));?>
Below is a sample of displaying the widgets on a sidebar:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(1) ) : ?>But there is still a lingering question in my mind, having worked with a lot of Joomla templates and its predecessor Mambo, I am used to the module positions where I could put it anywhere on the template, with a lot more ease and less pain than Wordpress. I could control the module without having to code heavily. The question is can you count the number of widgets in a sidebar. What I usually do in Joomla is count the modules in a module position if it is greater tha zero then the width of the other column would be much wider, or lets say that the sidebar will collapse or be invisible.
<?php endif; ?>
Anyway Wordpress seems to have an answer to this, you could either make a template for a specific page and by default there is the single.php page you could make which could not have any sidebars at all. Having said that maybe my next topic would be about templates.
Hi, I was looking for a way to count wordpress widgets. I didn't find a built in way but I realized I could do it with jquery.
ReplyDeleteBy using .size() to count the widget elements and then adding or removing classes on the couple elements of my page that depend on the number of widgets (for me, I only needed to change things if no widgets were available).
I think I'm going to play with it today, I'll be working on a wordpress theme adjustment today, thanks for the info.
ReplyDeleteI'm not really familiar with jquery but its going to be worth the while to play around.