你需要的是$GLOBALS[\'wp_query\']->max_num_pages
和get_pagenum_link()
. 那么你只需要比较一下get_query_var( \'paged\' )
具有max_num_pages
如果它们不相等,则创建链接:
/**
* Link to last page of a paged archive.
*
* @param string $text Link text
* @return string Nothing if we are on the last page, a link otherwise.
*/
function t5_get_last_posts_link( $text = \'Last Posts\' )
{
global $wp_query;
if ( // something is very wrong
! isset ( $wp_query->max_num_pages )
// there is just one page
or 1 == $last = $wp_query->max_num_pages
// we are already on the last page
or get_query_var( \'paged\' ) == $last
)
{
return \'\';
}
return sprintf( \'<a href="%1$s">%2$s</a>\', get_pagenum_link( $last ), $text );
}
/**
* Link to the first page of a paged archive.
*
* @param string $text Link text
* @return string Nothing if we are on the first page, a link otherwise.
*/
function t5_get_first_posts_link( $text = \'First Posts\' )
{
global $wp_query;
if ( // something is very wrong
! isset ( $wp_query->max_num_pages )
// there is just one page
or 1 == $wp_query->max_num_pages
// we are already on the first page
or 2 > (int) get_query_var( \'paged\' )
)
{
return \'\';
}
return sprintf( \'<a href="%1$s">%2$s</a>\', get_pagenum_link( 1 ), $text );
}
使用
print t5_get_first_posts_link( \'Newest\' );
print t5_get_last_posts_link( \'Oldest\' );
输出