I am a WP developer stuck in a bit of a spot right now.
I have set up a page with theme options in functions.php file... using the generic code. The options work well in the setup. But its a long list of options, so now i need to chop the file in three and have three options page showing up in dashboard instead of one.
need a quick solution to that problem.. this is the file i have used to make theme options.
[[LINK href="http://pastebin.com/mF0chvND"]]http://pastebin.com/mF0chvND[[/LINK]]
this is the code used in theme_options.php file and it is included in the functions.php file using the php include.
right now this file is generating a page on dashboard with expandable sections but client do not want that. he wants the options to be spread on three pages.
first page - left sidebar banner/ sidebar gif/flash
second page -flags
third page - partners listing [ 15 rows]
Jermaine Oppong answers:
Hello Ekta,
Can you please expanding on what you are asking for. If you are chopping the file in three options pages, what do you want to de displayed in each? Will the options pages appear under the Dashboard dropdown?
Ekta Paneri comments:
I have like 33 items in the array. i want 11 items to individually show up on one page. so its like there are 3 theme options page in the dashboard.
Jermaine Oppong comments:
Two Solutions.
The quickest solution I can recommend will be to create three different files, each with your options. Then change the contents of the array <strong>$options</strong> as appropriate for each file, so <strong>options1.php</strong> will have options 1-11, <strong>options2.php</strong> will have 12-22 then options3.php will be 22-32. Pretty much the same code will go in all files except maybe tweak the title within the <strong>add_theme_page()</strong> function so its <strong>theme Options 2</strong>, <strong>theme Options 3</strong>. Looking at the code Im assuming this menu will appear under the 'Appearance' section.
The second idea is doing everything in the same theme file, which can be confusing, but it involves repeating the code snippet you linked to, but changing the <strong>$options</strong> variable into a different variable name for each 11, and tweaking the functions to recognise that as well.
Let me know if you understand this. If not then I can do this for a willingness to invest more.
Jermaine Oppong comments:
Sorry I think I may get it now after reading your reply to Tobias. You basically want the single theme options page to be split into three sections within that same theme page. You can do this with some form of tabbed divs and javascript or you can use a URL query string so you get something like
http://www.your-site.com/wp-admin/themes.php?page=theme-options.php&<strong>sub=theme-options-2</strong>
So basically you set menus at the top of the Options page like:
Section 1 | Section 2 | Section 3
and change the $sub variable for section 2 and section 3. You set a query string variable in the URL called <strong>$sub</strong> which will change the page output. You will need to use the $_GET['sub'] superglobal and change the arrays displayed. Am I getting there?
Jermaine Oppong comments:
In simple terms
if ($_GET['sub'] == 'section-2'){
// display array options from 11 to 22
}
if ($_GET['sub'] == 'section-3'){
// display array options from 22 to 33
}
The Section 1 hyperlink will have no <strong>$sub</strong> variable in its query string cos its not needed.
Jermaine Oppong comments:
In simple terms
if ($_GET['sub'] == 'section-2'){
// display array options from 11 to 22
}
if ($_GET['sub'] == 'section-3'){
// display array options from 22 to 33
}
The Section 1 hyperlink will have no <strong>$sub</strong> variable in its query string cos its not needed.
Jermaine Oppong comments:
Simply put, do something like this:
if(!$_GET['sub']){
// display array options from 1-11
} elseif ($_GET['sub'] == 'section-2'){
// display array options from 12 to 22
}elseif ($_GET['sub'] == 'section-3'){
// display array options from 23 to 33
}
Ekta Paneri comments:
Jermine, I have tried the same trick with a help of a netuts tutorial for an advanced wp theme options page. it doesn't work.
Jermaine Oppong comments:
Can you attach the code you've been using so far?
Ekta Paneri comments:
http://pastebin.com/mF0chvND
this is the code used in theme_options.php file and it is included in the functions.php file using the php include.
right now this file is generating a page on dashboard with expandable sections but client do not want that. he wants the options to be spread on three pages.
first page - left sidebar banner/ sidebar gif/flash
second page -flags
third page - partners listing [ 15 rows]
Tobias Nyholm answers:
It's a bit tricky to understand how to add admin menus but here is some code, I bet you understand it by reading it. Or else, there is good documentation on these function.
function my_menu() {
$page=array();
//Add a new top-menu
//The following two lines must have the same URL and function. (last two param)
add_menu_page("MyOptions", "MyOptionsTitle", 'manage_options', 'MyOptions-URL', 'my_admin_main');
$page[]=add_submenu_page('MyOptions-URL','General options Title', 'General options', 'manage_options', 'MyOptions-URL', 'my_admin_main');
//Add some submenus
//parent, title, link, rights, url, function
$page[]=add_submenu_page('MyOptions-URL', "Option page1 Title", "Option page1",'manage_options',"Option-page1", 'my_admin_option1');
$page[]=add_submenu_page('MyOptions-URL', "Option page2 Title", "Option page2",'manage_options',"Option-page2", 'my_admin_option2');
//to add style sheets to your pages, and your pages only:
foreach($page as $p)
add_action('admin_print_styles-' . $p, 'my_admin_styles');
}
add_action('admin_menu', 'my_menu');
function sbc_admin_styles(){
wp_register_style('myStyleAdmin', WP_PLUGIN_URL . '/myPlugin/includes/admin.css');
}
function my_admin_main(){
echo "Main option page";
}
function my_admin_option1{
echo "Option page 1";
}
function my_admin_option2{
echo "Option page 2";
}
Ekta Paneri comments:
Its not creating the admin menu thats a prob. i have been reading up a lot about it all over the place and have been able to make those pages. where i am stuck is the division of array of options on pages so that some of them shows on first and remaining show on other two.
Denzel Chia answers:
Hi,
The codes you are using is created by woo themes for their theme options.
It is being copied by many so call WordPress experts in their tutorials.
It is not the "generic code" for creating an option settings page.
You should use the WordPress Settings API instead. Which is easy to understand and you can create as many option pages you like, once you understands it.
You can read the tutorial here http://ottodestruct.com/blog/2009/wordpress-settings-api-tutorial/ and the settings API codex here http://codex.wordpress.org/Settings_API
If you insist on using your pastebin script for many option pages. Simply rename the whole set of functions for each page and you will be able to create more than one option page.
Thanks.
Sharon Chambers answers:
Hi Ekta.
If you reorganize your existing code into three separate functions in this form (using left sidebar banner as example):
<?php
add_action('admin_menu', 'left_sidebar_banner');
function left_sidebar_banner() {
add_options_page('Title for Left Sidebar Banner', 'Theme Name', 'manage_options', 'my-unique-identifier', 'left_sidebar_banner_opts');
}
function left_sidebar_banner_opts() {
if (!current_user_can('manage_options')) {
wp_die( __('You do not have sufficient permissions to access this page.') );
}
echo '<div class="wrap">';
echo '<p>Here is where the form would for all your banner options.</p>';
echo '</div>';
}
?>
Note that this line: add_action('admin_menu', 'left_sidebar_banner');
denotes the wordpress "hook", telling wordpress that whenever the admin menu is displayed, you want to call the following function (which will add/display your options page). So you would create a separate action, and separate handling functions for each of your pages.
Ekta Paneri comments:
i tried that too. although the reorganizing is the part i am stuck at. it only shows the first page in the hook, and the other two doesnt show.
can you elaborate over the reorganizing part?