WordPress 分页 - 添加锚链接

2022-01-04 00:00:00 php wordpress html pagination anchor

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

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

这是我的分页代码:

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

解决方案

解决方案 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/

相关文章