treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Wordpress Theme Option Problem

  • Hi,

    I'm having some problems with my theme-options.php & now I'm unable to edit any of appearance options nor the website opens . My Wordpress Site: http://www.dryerventcleaninghouston.com/

    This is where the error occurs:

        <div class="postbox">
      <h3><?php _e("Homepage Featured Left", 'studiopress'); ?></h3>
        <div class="inside">
          <p><?php _e("Select which category you want displayed:", 'studiopress'); ?><br />
            <?php wp_dropdown_categories(array('selected' => get_theme_mod('featured_top_left'), 'name' => $settings.'[featured_top_left]', 'orderby' => 'Name' , 'hierarchical' => 1, 'hide_empty' => '0' )); ?></p>
    
          <p><?php _e("Number of posts to show:", 'studiopress'); ?><br />
          <input type="text" name="<?php echo $settings; ?>[featured_top_left_num]" value="<?php echo get_theme_mod('featured_top_left_num'); ?>" size="5" /></p>
    
          <p><?php _e("Thumbnail dimensions (Width x Height)", 'studiopress'); ?><br />
          <input type="text" name="<?php echo $settings; ?>[featured_top_left_thumb_width]" value="<?php echo get_theme_mod('featured_top_left_thumb_width'); ?>" size="3" /> x <input type="text" name="<?php echo $settings; ?>[featured_top_left_thumb_height]" value="<?php echo get_theme_mod('featured_top_left_thumb_height'); ?>" size="3" /></p>
        </div>
      </div>
    

    Thanks.

  • @Tahirk What is on line 88?

    Shouldn't it be

    <?php wp_dropdown_categories(array('selected' => get_theme_mod('featured_top_left'), 'name' => $settings['featured_top_left'], 'orderby' => 'Name' , 'hierarchical' => 1, 'hide_empty' => '0' )); ?></p>

  • Thanks Christopher. On line 88 I have this:

    <input type="text" name="<?php echo $settings; ?>[featured_top_left_num]" value="<?php echo get_theme_mod('featured_top_left_num'); ?>" size="5" />
    
  • @tahirk Hmm. Try my suggestion above. If that doesn't work, keep the change but also try this:

    <input type="text" name="<?php echo $settings['featured_top_left_num']; ?>" value="<?php echo get_theme_mod('featured_top_left_num'); ?>" size="5" />

  • Thanks a lot for your help, I'm still facing some problems:

    Basically at first I was having some problems with setting the number of posts to show as they would reset to 3 as soon as I set it to 5. So I tried to edit & it bite me back.

  • 
    
    <?php
    /*
    Plugin Name: Theme Options
    Author: Nathan Rice
    Author URI: <a href="http://www.nathanrice.net/" target="_blank" rel="nofollow">http://www.nathanrice.net/
    
    NOTE: this file requires WordPress 2.7+ to function
    */
    $settings = 'mods_'.get_current_theme(); // do not change!
    
    $defaults = array( // define our defaults
        'header_blog_title' => 'Image',
        'featured_top_left' => 1,
        'featured_top_left_num' => 5,
        'featured_top_left_thumb_width' => 100,
        'featured_top_left_thumb_height' => 100,
        'blog_cat' => 1,
        'blog_cat_num' => 5 // <-- no comma after the last option
    );
    
    //  push the defaults to the options database,
    //  if options don't yet exist there.
    add_option($settings, $defaults, '', 'yes');
    
    /*
    ///////////////////////////////////////////////
    This section hooks the proper functions
    to the proper actions in WordPress
    \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    */
    //  this function registers our settings in the db
    add_action('admin_init', 'register_theme_settings');
    function register_theme_settings() {
      global $settings;
      register_setting($settings, $settings);
    }
    //  this function adds the settings page to the Appearance tab
    add_action('admin_menu', 'add_theme_options_menu');
    function add_theme_options_menu() {
      add_submenu_page('themes.php', 'Education '.__('Theme Options','studiopress'), 'Education '.__('Theme Options','studiopress'), 8, 'theme-options', 'theme_settings_admin');
    }
    
    /*
    ///////////////////////////////////////////////
    This section handles all the admin page
    output (forms, update notifications, etc.)
    \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    */
    function theme_settings_admin() { ?>
    <?php theme_options_css_js(); ?>
    
    <?php
      // display the proper notification if Saved/Reset
      global $settings, $defaults;
      if(get_theme_mod('reset')) {
        echo '<div class="updated fade" id="message">'.__('Theme Options', 'studiopress').' '.__('RESET TO DEFAULTS', 'studiopress').'';
        update_option($settings, $defaults);
      } elseif($_REQUEST['updated'] == 'true') {
        echo ''.__('Theme Options', 'studiopress').' '.__('SAVED', 'studiopress').'';
      }
      // display icon next to page title
      screen_icon('options-general');
    ?>
      <?php echo get_current_theme() . ' '; _e('Theme Options', 'studiopress'); ?>
      
      <?php settings_fields($settings); // important! ?>
      
      <?php // first column ?>
      
        
        <?php _e("Header Blog Title"); ?>
          
            <?php _e("Select from the following:", 'studiopress'); ?>
    <?php _e("Homepage Featured Left", 'studiopress'); ?> <?php _e("Select which category you want displayed:", 'studiopress'); ?>
    <?php wp_dropdown_categories(array('selected' => get_theme_mod('featured_top_left'), 'name' => $settings['featured_top_left'], 'orderby' => 'Name' , 'hierarchical' => 1, 'hide_empty' => '0' )); ?> <?php _e("Number of posts to show:", 'studiopress'); ?>
    " value="<?php echo get_theme_mod('featured_top_left_num'); ?>" size="5" /> <?php _e("Thumbnail dimensions (Width x Height)", 'studiopress'); ?>
    [featured_top_left_thumb_width]" value="<?php echo get_theme_mod('featured_top_left_thumb_width'); ?>" size="3" /> x [featured_top_left_thumb_height]" value="<?php echo get_theme_mod('featured_top_left_thumb_height'); ?>" size="3" /> <?php _e("Blog Page Template", 'studiopress'); ?> <?php _e("Select which category you want displayed:", 'studiopress'); ?>
    <?php wp_dropdown_categories(array('selected' => get_theme_mod('blog_cat'), 'name' => $settings.'[blog_cat]', 'orderby' => 'Name' , 'hierarchical' => 1, 'show_option_all' => __("All Categories", 'studiopress'), 'hide_empty' => '0' )); ?> <?php _e("Number of Posts to Show:", 'studiopress'); ?>
    [blog_cat_num]" value="<?php echo get_theme_mod('blog_cat_num'); ?>" size="3" /> " /> [reset]" value="<?php _e('Reset Settings', 'studiopress'); ?>" /> .metabox-holder { width: 350px; float: left; margin: 0; padding: 0 10px 0 0; } .metabox-holder .postbox .inside { padding: 0 10px; } CSS; echo jQuery(document).ready(function($) { $(".fade").fadeIn(1000).fadeTo(1000, 1).fadeOut(1000); }); JS; } ?>
  • May I ask why you're editing a plugin file? This is usually not recommended. Plus, '[]' seems to happen a lot in that code. From the very little knowledge I have with PHP, I thought it was supposed to go like this: ['']