dongrong7883 2015-08-30 13:07
浏览 76
已采纳

修改next_posts_link(); Wordpress中的URL包含#hash扩展名

Am looking for a good method to add a #hash to Wordpress Paged Navigation

The basic code, something like this

<nav id="<?php echo $html_id; ?>" class="navigation" role="navigation">
    <ul>
        <li class="previous">
             <?php next_posts_link( __( '<span class="meta-nav">Load more</span>', '' ) ); ?>
       </li>
  </ul>

Output

http://myurl.com/page/2/

Problem

Am running 3 individual queries on index page so i would need to add a #hash to the url to make it load the right content. Am looking for a built in function or other smart / light way of achieving a url for my next_posts_link( ); looking something like this

http://myurl.com/page/2/#hash

Have been looking around but most solutions gravitate around breaking it apart, modify and rebuild. It works well but am thinking there must be a better way!!

Any smart suggestions?

  • 写回答

1条回答 默认 最新

  • doukuanghuan7582 2015-08-30 13:13
    关注

    You could try

    add_filter('next_post_link', 'changemylink');
    
    function changemylink($link) 
    {
        //you can also do some checks here, like if you want it to only be replaced on specific page or for specific post type, etc
        return preg_replace('#(href=["\']?[^"\'>]+)(["\']?)#','$1#yourtag$2',$output)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计