简体   繁体   English

自定义永久链接的WordPress分页

[英]wordpress pagination with custom permalinks

I use this "custom" pagination script for my wordpress template: 我为我的wordpress模板使用此“自定义”分页脚本:

$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('showposts='.get_option( 'posts_per_page' ).'&paged='.$paged);

while ($wp_query->have_posts()) : $wp_query->the_post();
    echo '<a class="current";
    echo '" href="';
    the_permalink();
    echo '">';
    the_title();
    echo '</a>';
endwhile;
next_posts_link('Load more articles...'); 
$wp_query = null; $wp_query = $temp;

So in the end, it creates a "load more" button that goes to http://blog.com /page/2 Now the problem is that with custom permalinks the url resembles this: http://blog.com /custom/stuff /page/2 which breaks the script and does not display the next result but the originals. 所以,最后,它创建了一个“加载更多”按钮进入http://blog.com / /第2页现在的问题是,自定义永久链接的网址类似于此: http://blog.com /自定义/ stuff / page / 2,它会破坏脚本,并且不显示下一个结果,而是原始结果。

Might nay of you know how I can fix this? 可能不会,您知道我该如何解决? or maybe force http://blog.com /page/2 in functions.php? 还是可能在functions.php中强制http://blog.com / page / 2

Thanks for your help guys! 感谢您的帮助!

I was having the same problem for ages and then tried setting this in my custom permalink settings which worked for me: /%postname%/. 我多年来一直遇到相同的问题,然后尝试在对我有用的自定义永久链接设置中进行设置:/%postname%/。

The dot after the last / is essential to get it working. 最后一个/后面的点对于使其工作至关重要。 Maybe not that pretty but hey it works for me :-) 也许不是那么漂亮,但是嘿,它对我有用:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM