Advertisement
AnotnoyOxy

Wordpress Tabs

Jun 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.80 KB | None | 0 0
  1. <?php
  2. function title_pagination($atts, $content=null) {
  3.     ob_start();
  4.     ?>
  5.     <!-- Include jquery ui css -->
  6.     <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  7.     <!-- Include Jquery 1.12.4 -->
  8.     <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  9.     <!-- Include Jquery UI -->
  10.     <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  11.     <!-- Script -->
  12.     <script>
  13.         $(function() {
  14.             $("#tabs").tabs();
  15.         });
  16.     </script>
  17.  
  18.     <?php
  19.     if ($content != null) {
  20.         // Remove new line from content
  21.         $string = str_replace("\n", '', $content);
  22.         // regex h3 element -> end div element
  23.         preg_match('/<h3>(.*)<\/div>/', $string, $matches);
  24.         // append h3 element to $matches[1] array
  25.         $match = '<h3>' . $matches[1];
  26.         // explode h3 element from $match variable
  27.         $explode = explode('<h3>', $match);
  28.  
  29.         // Tabs
  30.         echo '<div id="tabs">';
  31.         echo '<ul>';
  32.         // Tabs Pagination
  33.         foreach($explode as $key => $value) {
  34.             // Key Start from 0
  35.             // If $key != 0 then echo tab number
  36.             if ($key != 0) {
  37.                 echo '<li><a href="#tabs-'. $key .'">'. $key .'</a></li>';
  38.             }
  39.         }
  40.         echo '</ul>';
  41.         // Tabs Content
  42.         foreach($explode as $key => $value) {
  43.                 echo '<div id="tabs-'. $key .'">';
  44.                 echo '<h3 class="head-'. $key .'">' . $value;
  45.                 echo '</div>';
  46.         }
  47.         echo '</div>';
  48.  
  49.     } else {
  50.         echo 'Does Not Exist!';
  51.     }
  52.     $output = ob_get_clean(); //Get current buffer contents and delete current output buffer
  53.     return $output;
  54. }
  55.  
  56. add_shortcode('title-pagination','title_pagination');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement