Guest User

Untitled

a guest
Jul 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: Next Previous button bootstrap
  4. * Description: Super simple plugin to add next and Previous button
  5. * Version: 1.0.0
  6. * Author: Abdus Sattar Bhuiyan
  7. * Author URI: https://www.facebook.com/abdus.s.bhuiyan
  8. */
  9.  
  10. $cat = get_the_category($id);
  11. print_r($cat); exit;
  12. $cat = $cat[0];
  13. $menu_slug = strtolower($cat->name);
  14.  
  15. $menuitems = wp_get_nav_menu_items( $menu_slug, array( 'order' => 'DESC' ) );
  16.  
  17. $i=-1;
  18. foreach ( $menuitems as $item ):
  19. if($item->url =='#')
  20. continue;
  21.  
  22. $i++;
  23.  
  24. $id = get_post_meta( $item->ID, '_menu_item_object_id', true );
  25. $page = get_page( $id );
  26. $link = get_page_link( $id );
  27.  
  28. $linkarray.=$id.",";
  29. $urlarray.=$link.",";
  30.  
  31. if ($id==$post->ID){
  32. $previd=$i-1;
  33. $nextid=$i+1;
  34. }
  35. endforeach;
  36.  
  37. $linkarray=explode(',',$linkarray);
  38. $urlarray=explode(',',$urlarray);
  39.  
  40. $nextid=$urlarray[$nextid];
  41. if (empty($nextid)){
  42. $nextid=$urlarray[0];
  43. }
  44. $previd=$urlarray[$previd];
  45. if (empty($previd)){
  46. $previd=$urlarray[$i];
  47. }
  48.  
  49. $next_prev_btn = '<a href="<?php echo $nextid; ?>">Next Item</a>';
  50. $next_prev_btn .= '<a href="<?php echo $previd; ?>">Previous Item</a>';
  51.  
  52.  
  53. add_filter( 'the_content', 'add_next_prev_btn' );
  54.  
  55. function add_next_prev_btn( $content ) {
  56. return $content . $next_prev_btn;
  57. }
Add Comment
Please, Sign In to add comment