Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php
  2. if (is_single() && in_category('stories')) {
  3. $post_id = $post->ID;
  4. $cat = get_the_category(); //I've tried changing this to my category (both ID and slug)
  5. $current_cat_id = $cat[0]->cat_ID; //Also tried plugging ID and slug
  6.  
  7. $args = array(
  8. 'category' => $current_cat_id, //Also tried plugging ID and slug
  9. 'orderby' => 'post_date',
  10. 'order' => 'DESC'
  11. );
  12. $posts = get_posts($args);
  13.  
  14. $ids = array();
  15. foreach ($posts as $thepost) {
  16. $ids[] = $thepost->ID;
  17. }
  18.  
  19. $thisindex = array_search($post_id, $ids);
  20. $previd = $ids[$thisindex - 1];
  21. $nextid = $ids[$thisindex + 1];
  22.  
  23. if (!empty($nextid)) {
  24. ?><div class="double-grid"><a rel="next" href="<?php echo get_permalink($nextid) ?>"><div class="image-tile tile-on-archive-page" style="background-image: url('<?php echo get_the_post_thumbnail_url($nextid); ?>'"> <div class="gold-button">LAST STORY >></div></div></a></div><?php
  25. }
  26. if (!empty($previd)) {
  27. ?><div class="double-grid"><a rel="prev" href="<?php echo get_permalink($previd) ?>"><div class="image-tile tile-on-archive-page" style="background-image: url('<?php echo get_the_post_thumbnail_url($previd); ?>'"> <div class="gold-button">NEXT STORY >></div></div></a></div><?php
  28. }
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement