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.

The question is pretty simple, but it's complex in fact.

I have implemented custom sidebars for each post/page function in my blog.

It looks like:

<div id="<?php echo get_option('sidebar-layout');" ?>
 <div id="content">
   Some content
   [myshortcode]
 </div>
 <div id="sidebar">
   Sidebar 
 </div>
</div>

sidebar-layout option can have three values - left, right and none. And none is default. They are all set via metabox under post/page.

The biggest problem here is that when user chooses left - the first div gets "left" class and everything else is based on this ID, eg.

#left #content {
     style;
}

And when he takes "right" then different style is applied:

#right #content {
     another style;
}

So my "myshortcode" should basically change parents DIV id.

Any ideas how to achieve that? I believe my shortcode will be executed AFTER the div ID.

share|improve this question
1  
Can you explain the link between your shortcode and your sidebar-layout setting? The way you describe it, it looks like you use post metadata. Your code example uses get_option() which reads site-wide options. –  Jan Fabry Apr 6 '11 at 12:34
add comment

1 Answer

up vote 1 down vote accepted

Use this code to echo your div's ID

<?php $sidebar_layout = get_post_meta($post->ID, 'sidebar-layout', $single = true); ?>
<div id="<?php echo $sidebar_layout ?>">
    <div class="content">
         ...
    </div>
    <div class="sidebar">
    ...
    </div>
</div>

If you want to apply styles according to the selection the user has made then change your style sheet as follows:

#left .content{ ... }
#left .sidebar{ ... }
#right .content{ ... }
#right .sidebar{ ... }
#none .content{ ... }
#none .sidebar{ ... }

I hope this helps.

share|improve this answer
add comment

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.