Stn
Stn

Reputation: 447

How do you create a "next page" link in Wordpress?

I'm trying to add a button to my site which links to the next page of posts. I'm looking for a way to add an HTML link to the button so it actually works.

http://codex.wordpress.org/Template_Tags/wp_link_pages

I believe that explains what I want, but I'm not having any luck trying to get those snippets to work.

My button looks like:

<a href="#" class="next_page">Next Page</a> 

How can I link the button to the next page function in Wordpress?

EDIT:

My problem is I can't figure out how to associate this code with a button.

Upvotes: 2

Views: 16196

Answers (3)

Freddy
Freddy

Reputation: 442

There are two 'built-in' ways of doing this in Wordpress:

1) If you need access to the link as a PHP variable, try Using get_next_posts_link

<?php $nextLink = get_next_posts_link( $label , $max_pages ); ?>
<?php $previousLink = get_previous_posts_link( $label ); ?>

From here the links are stored in variables and you can do whatever you'd like with them.

2) Otherwise use these:

<?php next_posts_link( $label , $max_pages ); ?>
<?php previous_posts_link( $label ); ?>

Where $label is the name of the link ( "Next Page" in your case ) and $max_pages is the max number of pages (if you want a limit), that the link shows up on.

If you want to style these, without having to enclose them inside another DIV, use Wordpress Filters

function apply_my_next_link_style ( ){
    return 'class="button"';
}
apply_filters( 'next_posts_link_attributes', 'apply_my_next_link_style' )

3) If you need even more control you can try this, from the source code for the above functions:

if ( !is_single() ) {
    echo '<a href="' . next_posts( 0, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', "Next Page") . '</a>';
}

Also, I would suggest asking these types of questions over at wordpress.stackexchange.com

Upvotes: 3

David Nguyen
David Nguyen

Reputation: 8528

<?php next_posts_link('Older Posts'); ?>   
<?php previous_posts_link('Newer Posts'); ?>

Upvotes: 0

Ernesto Marrero
Ernesto Marrero

Reputation: 132

Is necesary Snippets , visit this and this solve

Upvotes: 0

Related Questions