WordPress 分页 - 添加锚链接 [英] WordPress pagination - Adding an Anchor link

查看:23
本文介绍了WordPress 分页 - 添加锚链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 index.php 中有这个锚链接:

我希望此锚链接在单击 next_posts_link 和 previous_posts_link 时起作用,因此它不会一直到达页面顶部.不过,我不知道如何为 WordPress 分页执行此操作.

这是我的分页代码:

解决方案

解决方案 2:

使用 jQuery 将锚标记 #blog 添加到博客文章中的上一个/下一个链接

演示:http://jsfiddle.net/mfeldheim/EkMfP/12/

I have this anchor link in my index.php:

<a name="blog"></a>

I would like this anchor link to work When next_posts_link and previous_posts_link are clicked on so it doesn't go all the way to the top of the page. I have no idea how to go about doing this for WordPress pagination though.

Here is my code for the pagination:

<div class="pagenavi">
<?php if( function_exists( 'wp_pagenavi ' ) ) {
wp_pagenavi();
} else {
next_posts_link ('<div class="arrow-back"></div>'); }
previous_posts_link('<div class="arrow-forward"></div>') ; }

解决方案

Solution 2:

Adding anchor tag #blog to the prev/next links in a blogpost using jQuery

<script type="text/javascript">
$(document).ready(function() {
    $('.pagenavi a').each(function(i,a){$(a).attr('href',$(a).attr('href')+'#blog')});
});
</script>

Demo: http://jsfiddle.net/mfeldheim/EkMfP/12/

这篇关于WordPress 分页 - 添加锚链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆