Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function title_pagination($atts, $content=null) {
- ob_start();
- ?>
- <!-- Include jquery ui css -->
- <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
- <!-- Include Jquery 1.12.4 -->
- <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
- <!-- Include Jquery UI -->
- <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
- <!-- Script -->
- <script>
- $(function() {
- $("#tabs").tabs();
- });
- </script>
- <?php
- if ($content != null) {
- // Remove new line from content
- $string = str_replace("\n", '', $content);
- // regex h3 element -> end div element
- preg_match('/<h3>(.*)<\/div>/', $string, $matches);
- // append h3 element to $matches[1] array
- $match = '<h3>' . $matches[1];
- // explode h3 element from $match variable
- $explode = explode('<h3>', $match);
- // Tabs
- echo '<div id="tabs">';
- echo '<ul>';
- // Tabs Pagination
- foreach($explode as $key => $value) {
- // Key Start from 0
- // If $key != 0 then echo tab number
- if ($key != 0) {
- echo '<li><a href="#tabs-'. $key .'">'. $key .'</a></li>';
- }
- }
- echo '</ul>';
- // Tabs Content
- foreach($explode as $key => $value) {
- echo '<div id="tabs-'. $key .'">';
- echo '<h3 class="head-'. $key .'">' . $value;
- echo '</div>';
- }
- echo '</div>';
- } else {
- echo 'Does Not Exist!';
- }
- $output = ob_get_clean(); //Get current buffer contents and delete current output buffer
- return $output;
- }
- add_shortcode('title-pagination','title_pagination');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement