Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Need help finishing tabbed meta options for my theme WordPress

  • SOLVED

Hey everyone, I'm finishing up some big improvements to my theme's meta options and am having trouble finalizing the tabs I have added. I think I need some help with a foreach function, but I'll let you guys decide seeing as you are the experts here :) I'm using some javascript which controls the tabs, which I register and enqueue at the bottom of the file. I don't think I need to include my entire meta options code, so I'll just include the parts in question.

Here is the part which actually controls what shows up on the screen:

// Callback function to show fields in meta box
function show() {
global $post;

wp_nonce_field(basename(__FILE__), 'rw_meta_box_nonce');
echo '<div class="metabox-tabs-div">';
echo '<ul class="metabox-tabs" id="metabox-tabs">';
echo '<li class="active tab1"><a class="active" href="javascript:void(null);">Feature Slider</a></li>';
echo '<li class="tab2"><a href="javascript:void(null);">Sidebar</a></li>';
echo '<li class="tab3"><a href="javascript:void(null);">SEO</a></li>';
echo '</ul>';

foreach ($this->_fields as $field) {
$meta = get_post_meta($post->ID, $field['id'], !$field['multiple']);
$meta = !empty($meta) ? $meta : $field['std'];
<strong>$tab = 'tab1';

echo '<div class="', $tab,'">';</strong>
echo '<table class="form-table">';
echo '<tr class="test">';
// call separated methods for displaying each type of field
call_user_func(array(&$this, 'show_field_' . $field['type']), $field, $meta);
echo '</tr>';


echo '</table>';
echo '</div>';
}

echo '</div>';
}
/******************** END META BOX PAGE **********************/


I have added the tab classes, and the ul and li stuff, and added the $tab variable just to test to make sure everything is working properly. Right now I only have one option for pages, but I'm going to build out options for Sidebar stuff and for SEO. Now, the actual contents of these tabs are defined as follows:

add_action('init', 'ifeature_initialize_the_meta_boxes');

function ifeature_initialize_the_meta_boxes() {
$prefix = 'slider_';

$meta_boxes = array();

$meta_boxes[] = array(
'id' => 'feature',
'title' => 'iFeature Slider Options',
'pages' => array('post'),

'fields' => array(

array(
'name' => 'iFeature Slider Image',
'desc' => 'Upload your image here:',
'id' => $prefix . 'post_image',
'type' => 'image',
'std' => ''
),
array(
'name' => 'iFeature Slider Text',
'desc' => 'Enter your slider text here (optional):',
'id' => $prefix . 'text',
'type' => 'text',
'std' => ''
),
array(
'name' => 'Hide Title Bar',
'desc' => 'Click to disable the title bar on this slide:',
'id' => $prefix . 'hidetitle',
'type' => 'checkbox',
'std' => ''
),

)
);

$meta_boxes[] = array(
'id' => 'slides',
'title' => 'Custom Feature Slides',
'pages' => array('if_custom_slides'),

'fields' => array(

array(
'name' => 'Custom Slide Link',
'desc' => 'Enter your link here',
'id' => $prefix . 'url',
'type' => 'text',
'std' => ''
),
array(
'name' => 'Custom Slide Image',
'desc' => 'Upload your image here:',
'id' => $prefix . 'image',
'type' => 'image',
'std' => ''
),
array(
'name' => 'Hide Title Bar',
'desc' => 'Click to disable the title bar on this post:',
'id' => $prefix . 'hidetitle',
'type' => 'checkbox',
'std' => ''
),
)
);

$terms = get_terms('slide_categories', 'hide_empty=0');

$options = array();

foreach($terms as $term) {

$options[$term->slug] = $term->name;

}


$meta_boxes[] = array(
'id' => 'tab1',
'title' => 'Page Meta Options',
'pages' => array('page'),

'fields' => array(

array(
'name' => 'Slide Category',
'desc' => 'Select the slide category you would like to use',
'id' => $prefix . 'category',
'type' => 'select',
'options' => $options,
'std' => ''
),

)
);

foreach ($meta_boxes as $meta_box) {
$my_box = new RW_Meta_Box_Taxonomy($meta_box);
}
}


So it basically runs through the metabox.php, grabs the different cases (select, checkbox, textbox, radio, etc), and displays each box separately. The tabs are obviously going to put it into tabs instead of having 3 separate boxes.

The first two $meta_boxes[] arrays are for a custom post type and for posts, the third is the one in question (there will be more options obviously than just the category). What I want to do is to call the id of that array (in this case, tab1), and use that in the first part of the code I provided so that each array will be in it's own tab (the others will have an id of tab2 and tab3).

Again, at this point I've tested the code and everything is working. If I change my dummy variable to tab2 the Page Meta Options I have in place show up in tab2 instead of tab1, so I just need to call that id from the second array to use in the variable so that each section of meta options ends up in it's respective tab (at least that's the idea). In short my question is this: how do I call the IDs in these arrays to be used in a variable for these divs?

I hope this all made sense, and I'll be happy to post the entire meta options file/ send people the entire theme via email if they want to look at the entire thing. I'll also be happy to answer any other questions, I just need to get this last part taken care of so I can finish up my extended meta options for the next major release of this theme.


Answers (2)

2011-06-24

Utkarsh Kukreti answers:

If this hasn't been resolved yet, could you please email me too?


Utkarsh Kukreti comments:

You need to change the line

$tab = 'tab1';

to

$tab = $this->_meta_box['id'];


Tyler Cunningham comments:

That did the trick sir, thank you so much!

2011-06-24

Jerson Baguio answers:

Do you have a test platform? w/c we can see a running sample so it would easier to figure out. I am sending you a message with my email so you can send the template to my email for me to test..

thanks


Tyler Cunningham comments:

Email sent to the address you messaged me, thank you.