Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
<div class="sidebar_area">
<h4>Sponsor</h4>
<div class="sidebar_content">
    <ul>
        <li><a href="#">This is new post</a></li>
        <li><a href="#">This is new post</a></li>
        <li><a href="#">This is new post</a></li>
        <li><a href="#">This is new post</a></li>
        <li><a href="#">This is new post</a></li>
        <li><a href="#">This is new post</a></li>
    </ul>
</div>

I like to make my widget like this code. But problem is here I can't use widget content like bellow. How can I give sidebar content div with "sidebar_area" class.

<div class="sidebar_area">
<h4>Sponsor</h4>
<div class="sidebar_content">
    <!-- content goes here -->
</div>

share|improve this question
    
Should this <div class="sidebar_area"> be the sidebar container or the widget container? And what do you mean with I can't use widget content like below? –  t f Jan 18 at 13:08
    
widget container after title. –  Hasanuzzaman Jan 18 at 13:12
    
Hm? In your question you seem to be talking about sidebar_area, which comes before the title. So what is it? If you're looking for help here, you should consider writing more than just a short message... –  t f Jan 18 at 13:15
    
Sorry, Just a mistake. It should be <div class="sidebar_content"> –  Hasanuzzaman Jan 18 at 13:17

2 Answers 2

up vote 1 down vote accepted

If I understood you correctly, this is what you are trying to achieve:

register_sidebar(array(
    'name' => 'Sidebar Name',
    'id' => 'sidebar-id',
    'before_widget' => '<div class="sidebar_area">',
    'before_title' => '<h4>',
    'after_title' => '</h4><div class="sidebar_content">',
    'after_widget' => '</div></div>',
));

References:

share|improve this answer
    
It is ok. But problem is here if I don't use title in my sidebar widget than it will not work fine and create another problem. –  Hasanuzzaman Jan 18 at 13:27
    
Well, that's right. If you don't use titles at all, you can just move the second <div> into the before_widget parameter. If you use titles on some widgets, and not on some others, then there's no easy solution. –  t f Jan 18 at 13:30
    
Really it is a limitation of WordPress. –  Hasanuzzaman Jan 18 at 13:37
    
Well, not really. You can do this. It's just not done with some parameters. You would have to hook into dynamic_sidebar_params, then check for your sidebar, and adjust the params according to whether a title is present or not. –  t f Jan 18 at 13:43
    
hmm. Can you give me tutorial link about it . –  Hasanuzzaman Jan 18 at 13:50

Just register the sidebar and determine what to add before and after widget:

register_sidebar( array( 
    'name'          => __('My sidebar', 'cht'),
    'id'            => 'mysidebar',
    'class'         => 'sidebar_area',
    'before_widget' => '<div id="%1$s" class="sidebar_content %2$s">',
    'after_widget'  => "</div>\n",
    'before_title'  => '<h4>',
    'after_title'   => "</h4>\n"
));
share|improve this answer
    
"</div>\n" ?? What is n ? –  Hasanuzzaman Jan 18 at 13:22
    
UNIX end of a line - just... trust me it should be there. –  Borek Jan 18 at 13:24
    
How is the answer above better than mine - which BTW was posted 5 minutes earlier than the above one? –  Borek Jan 18 at 13:50
1  
All that \n does is format the generated markup, which is pointless. You are never going to edit the generated markup so the only thing that formatting it does is increase the size of the file that has to be transmitted to the browser. –  s_ha_dum Jan 18 at 16:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.