Can I use theme options to change two things at once?

Possible noob question — please be nice.

I’m doing up a theme options page using the sample from Themeshaper, and one of the options I want to have is to set the width of the sidebar.

Read More

To do this with the CSS I already have, I need to change class attributes in my HTML in two places (one for the main column width, one for the sidebar).

The Themeshaper code is fine for adding little theme option tweaks, but I can’t figure out how to get a single option to modify two places in the code at once.

Possibly (hopefully!) a simple question, but beyond my current abilities.

Any help greatly appreciated. Thanks.

Update:

I should clarify that I’m not a programmer, and I’m already waaay out of my depth. That said, here’s what I’m going for… In my theme options page, I want to have a drop-down menu with two options: ‘wide sidebar’ and ‘narrow sidebar’. One of these will be the default. Changing the default needs to modify two CSS classes. I appreciate Rarst’s answer below but I simply don’t know enough about PHP to be able to get it to work. Is there a simple(r) explanation for how to get this to happen? Again, sorry if this is basic stuff.

Related posts

Leave a Reply

1 comment

  1. Nothing prevents you from retrieving your option in several places. You can do several get_option() calls or create global variable and assign your value to it once.

    It is hard to come up with specific example without knowing what exactly you store in option and which classes you want to generate for your markup.

    Update

    One of the ways to get it done. Depending on how you organize code you might need to declare variables as global :

    $options = get_option('sample_theme_options');
    $sidebar_width = $options['sidebar_width']; // let's say we have stored integer '2' here
    $column_width = 8 - $sidebar_width; // total width minus sidebar
    
    // and then in template
    echo "<div class='main-{$column_width}col'> main </div>";
    echo "<div class='sidebar-{$sidebar_width}col'> sidebar </div>";