I’m using the following code to show one post in a page (Blog pages show at most is set to 1 post):
<?php
/**
* Template Name: Front Page
* @package WordPress
* @subpackage Prominent
* @since Prominent 1.0
*/
get_header(); ?>
<div id="tagline">
<div class="container">
</div><!-- .container -->
</div><!-- #tagline -->
<div id="content">
<div class="container">
<div id="mainbar">
<?php while ( have_posts() ) : the_post(); ?>
<div class="content-block-2">
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<?php next_posts_link( __( '← Older posts', 'twentyten' ) ); ?>
<?php previous_posts_link( __( 'Newer posts →', 'twentyten' ) ); ?>
<?php endif; ?>
</div><!-- #mainbar -->
</div><!-- .container -->
</div><!-- #content-bottom -->
<?php get_footer(); ?>
So now I got a prev and next link in my front page. I would like to know if is possible to add a first and latest posts link?
EDIT:
By First and Latest posts I mean, for instance,
Since I only allow one post per page, only one post will be shown.
I would like a link for post number 1 and 8 in the example below:
1 2 3 4 5 6 7 8
What you need are
$GLOBALS['wp_query']->max_num_pages
andget_pagenum_link()
. Then you just have to compareget_query_var( 'paged' )
withmax_num_pages
and create a link if they are not equal:Usage
Output
It appears like what you need is “pagination”. Install WP-PageNavi plugin, and add this in your template file (index.php, archive.php, etc. â whichever is relevant):
The plugin’s settings are self-explanatory. (HINT!
%PAGE_NUMBER%
)