ThemeShaper Forums » Thematic

[closed]

Adding Options to Child Theme

(9 posts)
  • Started 7 years ago by proto
  • Latest reply from em hr
  • This topic is not resolved
  1. proto
    Member

    Hello all,

    I was wondering if you any of you kind folks can help with me adding options to my child theme. I want to do two things:

    1: Add a drop down list in my child theme option that allows them to selection of a CSS stylesheet in child theme directory.

    2: Add a drop down menu that allows people to select any file in a given child theme directory.

    I think the following code adds a stylesheet directory to the header to be selected:

    <?php
    
    function wicked_load_custom_styles() {
      // load the custom options
      global $childoptions;
      foreach ($childoptions as $value) {
        $$value['id'] = get_option($value['id'], $value['std']);
      }
    
      wp_enqueue_style(
        'wicked-skin',
        get_bloginfo('stylesheet_directory').'/skins/'.$wicked_color_variant.'/skin.css',
        '', '', 'all'
      );
    } // end function
    
    add_action('wp_print_styles', 'wicked_load_custom_styles');
    
    ?>

    I think this how I populate my array of options for the stylesheet selector:

    array( "name" => __('Stylesheet','thematic'),
               "desc" => __('A stylesheet Selector for laying out the page','thematic'),
               "id" => "wicked_stylesheet_selector",
               "std" => $default_cat,
               "type" => "select",
               "options" => $stylesheet
        )

    I think this is how I add the actual options within my child theme options form:

    case 'select':
          ?>
          <tr valign="top">
            <th scope="row"><?php echo $value['name']; ?></th>
            <td>
              <select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
                <option value="">--</option>
                <?php foreach ($value['options'] as $key=>$option) {
                  if ($key == get_option($value['id'], $value['std']) ) {
                    $selected = "selected=\"selected\"";
                  } else {
                    $selected = "";
                  }
                ?>
                <option value="<?php echo $key ?>" <?php echo $selected ?>><?php echo $option; ?></option>
              <?php } ?>
              </select>
              <?php echo $value['desc']; ?>
            </td>
          </tr>
          <?php
          break;

    Trying to get these to all work together is proving difficult and I have been trying to get them to work but haven't quite managed it. What I'm hoping to do is

    1: Add a drop down list in my child theme option that allows them to selection of a CSS stylesheet in child theme directory.

    2: Add a drop down menu that allows people to select any file in a given child theme directory.

    Any help to achieve the above would be great and would hopefully help others too who want to add these sort of options to their child theme!

    Thank you :)

    Posted 7 years ago #
  2. currently there is no way to filter your own options into the thematic options. you have to create your own. my preferred method is to use Devin Price's plugin, Options Framework:

    http://wordpress.org/extend/plugins/options-framework/

    Posted 7 years ago #
  3. proto
    Member

    Thanks Helga,

    Much appreciated. I figured out how to add my stylesheets as options within my child theme.

    The only remaining problem I have is outputting one of a number custom loops on my homepage, depending which one I select in my designated childtheme directory via my theme options page.

    I've created an array to store my child theme options file layouts (custom loops)

    // the homepage layout
      $pixelwoo_homepage_layout = array(
        "magazine-one" => "magazine-one",
        "magazine-two" => "magazine-two",
      );
    
      $childoptions = array (
    
        array( "name" => __('Web Layout','thematic'),
               "desc" => __('(Select above which layout you would like to use for the homepage).','thematic'),
               "id" => "pixelwoo_home_layouts",
               "std" => 'magazine-one',
               "type" => "radio",
               "options" => $pixelwoo_homepage_layout
        ),

    I then output this in my child theme radio select box like so:

    //Options for selecting the homepage layout
    
    case "radio":
          ?>
          <tr valign="top">
            <th scope="row"><?php echo $value['name']; ?>:</th>
            <td>
              <?php foreach ($value['options'] as $key=>$option) {
                if ($key == get_option($value['id'], $value['std']) ) {
                  $checked = "checked=\"checked\"";
                } else {
                  $checked = "";
                }
                ?>
                <input type="radio" name="<?php echo $value['id']; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $option; ?>
              <?php } ?>
              <?php echo $value['desc']; ?>
            </td>
          </tr>
          <?php
          break;

    I then use an include function that calls my $pixelwoo_home_layouts in my home.php to get my custom homepage loops from their directory like so:

    include get_bloginfo('template_directory').'/directoryname/'.'layouts/'.$pixelwoo_home_layouts.'.php';

    My logic (probably flawed!!) was that my home.php file that uses the include will then select my home page loops that are called magazine-one.php (etc) that I click on in my child theme options page!

    I'd be grateful if someone could point out what's needed to make this work! :)

    Posted 7 years ago #
  4. proto
    Member

    I've tried changing my include function to the following, but it's still not working:

    include ('/library/homepage-layouts/'.$pixelwoo_home_layouts.'.php');

    Posted 7 years ago #
  5. proto
    Member

    include (STYLESHEETPATH .'/library/homepage-layouts/'.$pixelwoo_home_layouts.'.php');

    The above doesn't work either.

    Just to clarify if anyone can help. I'm aiming to store a number of different loops in a child theme directory each in their own file and name, eg:

    'magazine -one-layout.php'
    'magazine -two-layout.php'
    'magazine -three-layout.php'
    " etc...

    I then want to call any of these custom loops depending on which one I select in my child theme options. I've tried to replicate the success which I've got to work giving the user 5 stylesheets to choose from in my child theme options page, using the code above.

    The code above I've tried to adapt and use for calling a custom loop but something is not quite there. I'm sure this would help others who come after me thinking of doing the same thing as well, any help is greatly appreciated, thank you! :)

    Posted 7 years ago #
  6. huh? i only sort of follow you, but think this goes well beyond thematic. this is a more general WP type of question. if you are determined to do it yourself you might want to try asking for help at wordpress.stackexchange.com or the wordpress.org forums

    Posted 7 years ago #
  7. middlesister
    Member

    Have you stored the theme options in the database? It is not clear from your snippets how you store and retrieve your options. Are you using the Options Framwork that Helga linked to? If you are doing it manually, the best practice is to store all your options as a single array in the database.

    For your includes to work, the variable $pixelwoo_home_layouts needs to be set in home.php. I am guessing that it is not working because you try to use a variable that doesn't exist.

    I suggest you either use locate_template() to call your php files into home.php, or even better to keep the files in the theme root and use get_template_part().

    $pixelwoo_options = get_option( 'your_theme_option_id' );
    get_template_part( 'magazine', $pixelwoo_options['layout_option_id'] );

    So if your layout option value is 'layout-one', this would look for the file called 'magazine-layout-one.php' and include it.

    EDIT It looks like you _are_ storing it in the database, but each option separately. Try this in your home.php, with your template files in theme root.

    $layout = get_option( 'pixelwoo_home_layouts' );
    get_template_part( 'magazine', $layout );
    Posted 7 years ago #
  8. middlesister
    Member

    Oh, and similarly, you could simply use

    function wicked_load_custom_styles() {
    
      $skin = get_option( 'wicked_color_variant' );
    
      wp_enqueue_style(
        'wicked-skin',
        get_bloginfo('stylesheet_directory').'/skins/'.$skin.'/skin.css',
        '', '', 'all'
      );
    } // end function
    
    add_action('wp_print_styles', 'wicked_load_custom_styles');

    You don't need to loop through and query the database for every single option you have when all you are looking for is one of them.

    Posted 7 years ago #
  9. Hi everybody,

    For future reference the 0.9.7.8 rev777 Thematic (svn trunk at the time of this post) has introduced a rewrite of it's Theme Options using the WP Settings API. It's filterable and overridable. Checkout the latest svn and read the comments in the theme-options.php

    When it will get into the next release is unknown as it has to be passed through the WP Theme review process before going live in the repo.

    Posted 7 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.