I used to use the following code to make the list of all categories:
foreach($categories as $cat) {
print '<label>'.$cat->name.'</label>';
print '<input type="text" title="Add value" name="'.$themename.'_value_'.$cat->slug.'" id="'.$themename.'_color_'.$cat->slug.'" value="'.get_option($themename.'_value_'.$cat->slug).'" />';
}
It generates the list and unique input box for each category.
But I have rewritten the structure using arrays:
i.e.
$categories = get_categories('hide_empty=0&orderby=name');
$tz_wp_cats = array();
foreach ($categories as $category_list ) {
$tz_wp_cats[$category_list->cat_ID] = $category_list->cat_name;
}
array_unshift($tz_wp_cats, "Choose a category");
// ==========================//
// Start the theme options! //
// ==========================//
$themename = "Name";
$shortname = "tz";
$options = array (
array( "name" => __("selected", 'framework'),
"id" => $shortname."_selectedtab",
"std" => "",
"type" => "hidden"),
array( "type" => "opentab"),
array( "type" => "open"),
array( "name" => __("Banner Settings", 'framework'),
"id" => $shortname."_banner_settings",
"type" => "title"),
array( "name" => __("Show Header Advert", 'framework'),
"desc" => __("Check this to show a banner in the header of your site (468px x 60px)", 'framework'),
"id" => $shortname."_banner_header",
"std" => "false",
"type" => "checkbox"),
array( "name" => __("Banner Image URL", 'framework'),
"desc" => __("Enter the full image URL of your banner (468px x 60px) e.g. http://www.example.com/banner.gif", 'framework'),
"id" => $shortname."_banner_img_url",
"std" => get_bloginfo('template_directory')."/images/header_advert.jpg",
"type" => "text"),
It is the same structure as suggested on http://blog.themeforest.net/wordpress/create-an-options-page-for-your-wordpress-theme/
What would be the solution to rewrite the original way? Any suggestions?
(I have just a checkbox, text, textarea and file types)
To get a list of selectable categories use
wp_dropdown_categories()
.Example:
HTML output:
Visual output: