Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* -----------------------------------------------------------------
- Tab
- ----------------------------------------------------------------- */
- // Set up Scripts For Tabs
- function add_tabs_scripts_to_head(){
- wp_register_script( 'custom-script', get_template_directory_uri() . '/js/zozoTabs.js' );
- // For either a plugin or a theme, you can then enqueue the script:
- wp_enqueue_script( 'custom-script' );
- }
- // Set up Style For Tabs
- function add_tabs_style_to_head(){
- wp_register_style( 'custom-style', get_template_directory_uri() . '/css/zozoTabs.css');
- // For either a plugin or a theme, you can then enqueue the style:
- wp_enqueue_style( 'custom-style' );
- }
- add_action('template_redirect', 'add_scripts');
- extract(shortcode_atts(array(
- 'style' => false,
- 'orientation' => false,
- ), $atts));
- function add_scripts() {
- global $wp_query;
- if ( is_singular() ) {
- $post = $wp_query->get_queried_object();
- if ( false !== strpos($post->post_content, '[tabs') ) {
- // Adding the style JUST when needed
- add_action( 'wp_enqueue_scripts', 'add_tabs_style_to_head' );
- add_action( 'wp_enqueue_scripts', 'add_tabs_scripts_to_head' );
- }
- }
- }
- add_shortcode('tabs', 'ts_tab');
- function ts_tab($atts, $content = null, $code) {
- if (!preg_match_all("/(.?)\[(tab)\b(.*?)(?:(\/))?\](?:(.+?)\[\/tab\])?(.?)/s", $content, $count)) {
- return do_shortcode($content);
- } else {
- for($i = 0; $i < count($count[0]); $i++) {
- $count[3][$i] = shortcode_parse_atts($count[3][$i]);
- }
- $output = '
- <script>
- $(document).ready(function () {
- $("#tabbed-nav").zozoTabs({
- defaultTab: "tab1",
- rounded: false,
- });
- });
- </script>
- <div id="basic-usage">
- <div id="tabbed-nav">
- <ul>
- ';
- for($i = 0; $i < count($count[0]); $i++) {
- $output .= '<li><a>' . $count[3][$i]['title'] . '</a></li>';
- }
- $output .= '</ul>';
- $output .= '<div>';
- for($i = 0; $i < count($count[0]); $i++) {
- $output .= '<div>' . do_shortcode(trim($count[5][$i])) . '</div>';
- }
- $output .= '</div>';
- return '<div class="tabcontainer">' . $output . '</div></div></div>
- ';}
- }
Advertisement
Add Comment
Please, Sign In to add comment