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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀