Previous Post Link on index.php
-
I’ve been trying to figure this out for hours. I’ve built a theme that displays one post on the index page, and I don’t want users using the archive (/page/2/) next and prev links.
I’d like to link to the previous post, because once there, users will be on single.php, which supports next/prev post links.
Basically, I want a work around for this:
<?php previous_post_link('%link','« Previous',FALSE,'47') ?>
Without using this:
<?php posts_nav_link('','','« Previous') ?>
I’ve been trying to use something Otto wrote:
function get_next_post_id() { global $wp_query; if ($wp_query->$current_post == $wp_query->$post_count) return 0; $next_post = $wp_query->posts[$wp_query->$current_post - 1]; return $next_post->ID; }
In combination with this:
<a href="<?php echo get_permalink(); ?>" />« Previous</a>
And this:
<a href="<?php echo get_option('home'); ?>/<?php echo get_next_post_id(); ?>" />« Previous</a>
- The topic ‘Previous Post Link on index.php’ is closed to new replies.