james-riter

Untitled

Jul 18th, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1.  /* -----------------------------------------------------------------
  2.         Tab
  3. ----------------------------------------------------------------- */
  4.  
  5.  
  6.  // Set up Scripts For Tabs
  7.  function add_tabs_scripts_to_head(){
  8.     wp_register_script( 'custom-script', get_template_directory_uri() . '/js/zozoTabs.js' );
  9.     // For either a plugin or a theme, you can then enqueue the script:
  10.     wp_enqueue_script( 'custom-script' );
  11. }
  12.  
  13.  // Set up Style For Tabs
  14.  function add_tabs_style_to_head(){
  15.     wp_register_style( 'custom-style', get_template_directory_uri() . '/css/zozoTabs.css');
  16.     // For either a plugin or a theme, you can then enqueue the style:
  17.     wp_enqueue_style( 'custom-style' );
  18. }
  19.    
  20. add_action('template_redirect', 'add_scripts');
  21.  
  22. extract(shortcode_atts(array(
  23.         'style' => false,
  24.         'orientation' => false,
  25.     ), $atts));
  26.    
  27. function add_scripts() {
  28.    global $wp_query;
  29.    if ( is_singular() ) {
  30.       $post = $wp_query->get_queried_object();
  31.       if ( false !== strpos($post->post_content, '[tabs') ) {
  32.       // Adding the style JUST when needed
  33.       add_action( 'wp_enqueue_scripts', 'add_tabs_style_to_head' );
  34.       add_action( 'wp_enqueue_scripts', 'add_tabs_scripts_to_head' );
  35.       }
  36.    }
  37. }
  38. add_shortcode('tabs', 'ts_tab');
  39.     function ts_tab($atts, $content = null, $code) {
  40.     if (!preg_match_all("/(.?)\[(tab)\b(.*?)(?:(\/))?\](?:(.+?)\[\/tab\])?(.?)/s", $content, $count)) {
  41.         return do_shortcode($content);
  42.  
  43.     } else {
  44.         for($i = 0; $i < count($count[0]); $i++) {
  45.             $count[3][$i] = shortcode_parse_atts($count[3][$i]);
  46. }
  47. $output = '    
  48.     <script>
  49.         $(document).ready(function () {
  50.             $("#tabbed-nav").zozoTabs({
  51.                 defaultTab: "tab1",
  52.                 rounded: false,
  53.             });
  54.         });
  55.     </script>
  56.    
  57.     <div id="basic-usage">
  58.     <div id="tabbed-nav">
  59.     <ul>
  60. ';     
  61.     for($i = 0; $i < count($count[0]); $i++) {
  62.         $output .= '<li><a>' . $count[3][$i]['title'] . '</a></li>';
  63.     }
  64.     $output .= '</ul>';
  65.    
  66.     $output .= '<div>';
  67.     for($i = 0; $i < count($count[0]); $i++) {
  68.         $output .= '<div>' . do_shortcode(trim($count[5][$i])) . '</div>';
  69.     }
  70.     $output .= '</div>';
  71.     return '<div class="tabcontainer">' . $output . '</div></div></div>
  72.     ';}
  73. }
Advertisement
Add Comment
Please, Sign In to add comment