Hey guys!
I'm trying to create tabs using WordPress shortcodes and jQuery UI Tabs. I managed to get the tabs working but the code my shortcode functions output is in the wrong order. This is how it looks (functions.php):
// Tabs Main [tabs][/tabs]
function tabs_main($atts, $content = null) {
return '<div class="ui-tabs"><ul>' . do_shortcode($content) . '</ul></div>';
}
add_shortcode('tabs', 'tabs_main');
// Tab Elements [tab id="name"][/tab]
function tab_elements($atts, $content = null) {
extract(shortcode_atts(array(
'id' => 'Untitled Tab!'
), $atts));
return '<li><a href="#tab-' . $id . '"><span>' . $id . '</span></a></li>
<div id="tab-' . $id . '">' . $content . '</div>';
}
add_shortcode('tab', 'tab_elements');
Now it outputs like:
<div class="ui-tabs">
<ul>
<li><a href="#tab-1"><span>1</span></a></li>
<div id="tab-1"> Content goes here </div>
<li><a href="#tab-2"><span>2</span></a></li>
<div id="tab-2"> Content goes here </div>
</ul>
</div>
But it's supposed to look like this:
<div class="ui-tabs">
<ul>
<li><a href="#tab-1"><span>1</span></a></li>
<li><a href="#tab-2"><span>2</span></a></li>
</ul>
<div id="tab-1"> Content goes here </div>
<div id="tab-2"> Content goes here </div>
</div>
So I need to create two loops; the first one print out the list data (UL and LI) and the second one prints out the containers (DIV).
How do I do this?