static function get_next_post_link($id) { $args = array('posts_per_page' => -1, 'offset' => 0, 'category' => '', 'category_name' => '', 'orderby' => 'date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_mime_type' => '', 'post_parent' => '', 'author' => '', 'post_status' => 'publish', 'suppress_filters' => true); $posts_array = get_posts($args); self::$all_posts_id = array(); foreach ($posts_array as $key => $single) { array_push(self::$all_posts_id, $single->ID); } $index = ''; $link = '<ul>'; $prev = ''; $next = ''; $count = count(self::$all_posts_id); if (!empty(self::$all_posts_id)) { for ($i = 0; $i < $count; $i++) { if (self::$all_posts_id[$i] == $id) { $index = $i; break; } } if ($index == 0) { $prev = '<li class="prev"><a href="' . get_permalink(self::$all_posts_id[$count - 1]) . '"><i class="icon-left-open-big"></i></a></li>'; $next = '<li class="next"><a href="' . get_permalink(self::$all_posts_id[1]) . '"><i class="icon-right-open-big"></i></a></li>'; } elseif ($index == $count - 1) { $prev = '<li class="prev"><a href="' . get_permalink(self::$all_posts_id[$count - 2]) . '"><i class="icon-left-open-big"></i></a></li>'; $next = '<li class="next"><a href="' . get_permalink(self::$all_posts_id[0]) . '"><i class="icon-right-open-big"></i></a></li>'; } else { $prev = '<li class="prev"><a href="' . get_permalink(self::$all_posts_id[$index - 1]) . '"><i class="icon-left-open-big"></i></a></li>'; $next = '<li class="next"><a href="' . get_permalink(self::$all_posts_id[$index + 1]) . '"><i class="icon-right-open-big"></i></a></li>'; } } $link .= $prev . '<li><a href="#"><i class="icon-layout"></i></a></li>' . $next; $link .= '</ul>'; return $link; }