Adding a menu section through template function
-
Ok,
Currently I have a function which adds a submenu to the Appearance admin section called Opening Times.
What I’d really like to have though is another section like Appearance but called Theme Settings, then I can add Opening Times, Description etc to it and create a whole sub section for that particular template. I’ve looked at the codex but I can’t get my head around it as it’s more geared towards plugins – can anyone help add to the code to try and accomplish this task?
<?php class ControlPanel { var $default_settings = Array( 'day1' => 'Monday', 'time1' => '9:30-6:30' ); function ControlPanel() { add_action('admin_menu', array(&$this, 'admin_menu')); add_action('admin_head', array(&$this, 'admin_head')); if (!is_array(get_option('parkway'))) add_option('parkway', $this->default_settings); $this->options = get_option('parkway'); if (function_exists('register_sidebar')) register_sidebar(array('name' => 'Sidebar')); } function admin_menu() { add_theme_page('Parkway Options', 'Opening Times', 'edit_themes', "parkway", array(&$this, 'optionsmenu')); } function admin_head() { echo '<link rel="stylesheet" href="'.get_bloginfo('template_url').'/code/controlpanel.css" type="text/css" media="screen" />'; } function optionsmenu() { echo '<div id="icon-tools" class="icon32"><br /></div>'; echo '<div class="wrap">'; echo '<h2>Parkway Options</h2><br />'; echo '<h3>Opening Times</h3><hr color="lightgray" width="99%" align="left" size="1">'; if ($_POST['ss_action'] == 'save') { $this->options["day1"] = $_POST['cp_day1']; $this->options["time1"] = $_POST['cp_time1']; update_option('parkway', $this->options); echo '<div class="updated fade" id="message" style="background-color: rgb(255, 251, 204); width: 300px; margin-left: 20px"><p>Settings <strong>saved</strong>.</p></div>'; } echo '<form action="" method="post" class="themeform">'; echo '<input type="hidden" id="ss_action" name="ss_action" value="save">'; echo '<p>Day of the Week: <input class="widefat" style="text-align: right; width: 75px" name="cp_day1" id="cp_day1" type="text" value="'.$this->options["day1"].'" /></p>'; echo '<p>Time: <input class="widefat" style="text-align: right; width: 75px" name="cp_time1" id="time1" type="text" value="'.$this->options["time1"].'" /></p>'; echo '<p class="submit"><input type="submit" value="Save Changes" name="cp_save"/></p>'; echo '</form>'; echo '</div>'; } }Thanks a lot for your time.
Steve
-
Have you hooked in your ControlPanel function anywhere? I can’t see it in the code you’ve posted there, although I may have just missed it.
You’d want to hook in like this:
add_action('admin_menu', 'my_plugin_menu');replacing my_plugin_menu with your function name.
By the looks of things you’ve probably already read this, but following the instructions on this page – Adding Administration Menus, in your functions.php file should do the trick.
Sorry I’m stuggling with this – the code I had above I understand only a bit and I’ve read up on it but I’m still finding it hard to get my head around.
I’ve tried stuff on that page but when I add things in it keep goings blank so is obviously not working.
When you say hooked in my control panel – what does that mean and second what is my function name?
I’m probably diving in too deep here but I have something that needs to be complete this week so unfortunately I’ve been chucked in the deep end!
Appreicate any more guidance, thanks.
The topic ‘Adding a menu section through template function’ is closed to new replies.