Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: Next Previous button bootstrap
- * Description: Super simple plugin to add next and Previous button
- * Version: 1.0.0
- * Author: Abdus Sattar Bhuiyan
- * Author URI: https://www.facebook.com/abdus.s.bhuiyan
- */
- $cat = get_the_category($id);
- print_r($cat); exit;
- $cat = $cat[0];
- $menu_slug = strtolower($cat->name);
- $menuitems = wp_get_nav_menu_items( $menu_slug, array( 'order' => 'DESC' ) );
- $i=-1;
- foreach ( $menuitems as $item ):
- if($item->url =='#')
- continue;
- $i++;
- $id = get_post_meta( $item->ID, '_menu_item_object_id', true );
- $page = get_page( $id );
- $link = get_page_link( $id );
- $linkarray.=$id.",";
- $urlarray.=$link.",";
- if ($id==$post->ID){
- $previd=$i-1;
- $nextid=$i+1;
- }
- endforeach;
- $linkarray=explode(',',$linkarray);
- $urlarray=explode(',',$urlarray);
- $nextid=$urlarray[$nextid];
- if (empty($nextid)){
- $nextid=$urlarray[0];
- }
- $previd=$urlarray[$previd];
- if (empty($previd)){
- $previd=$urlarray[$i];
- }
- $next_prev_btn = '<a href="<?php echo $nextid; ?>">Next Item</a>';
- $next_prev_btn .= '<a href="<?php echo $previd; ?>">Previous Item</a>';
- add_filter( 'the_content', 'add_next_prev_btn' );
- function add_next_prev_btn( $content ) {
- return $content . $next_prev_btn;
- }
Add Comment
Please, Sign In to add comment