dougou7008
2012-10-31 19:12
浏览 70
已采纳

如何在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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douciping4283 2012-10-31 19:18
    已采纳

    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

    点赞 打赏 评论
  • dozr162106 2012-10-31 19:17

    Is necesary Snippets , visit this and this solve

    点赞 打赏 评论
  • douchun6108 2012-10-31 19:19
    <?php next_posts_link('Older Posts'); ?>   
    <?php previous_posts_link('Newer Posts'); ?>
    
    点赞 打赏 评论

相关推荐 更多相似问题