admin管理员组文章数量:1130349
Using get_next_posts_page_link function to get url of paginated post's next page url, but it's adding directories to it that simply do not exist.
Here is the code where I use it and probably missing something somewhere
while (have_posts()) : the_post();
the_content();
endwhile;
// echoing to see the actual url it would bring up if used in an anchor
echo get_next_posts_page_link();
And here are the urls
On page 1: mysitedomain/paginatedpage/page/2/ instead of mysitedomain/paginatedpage/2/
On page 2: mysitedomain/paginatedpage/2/page/2/ instead of mysitedomain/paginatedpage/3/
On page 3: mysitedomain/paginatedpage/3/page/2/ instead of mysitedomain/paginatedpage/4/
And so on...
Using get_next_posts_page_link function to get url of paginated post's next page url, but it's adding directories to it that simply do not exist.
Here is the code where I use it and probably missing something somewhere
while (have_posts()) : the_post();
the_content();
endwhile;
// echoing to see the actual url it would bring up if used in an anchor
echo get_next_posts_page_link();
And here are the urls
On page 1: mysitedomain/paginatedpage/page/2/ instead of mysitedomain/paginatedpage/2/
On page 2: mysitedomain/paginatedpage/2/page/2/ instead of mysitedomain/paginatedpage/3/
On page 3: mysitedomain/paginatedpage/3/page/2/ instead of mysitedomain/paginatedpage/4/
And so on...
Share Improve this question asked Nov 21, 2018 at 23:39 KunzhutKunzhut 32 bronze badges 4 |1 Answer
Reset to default 0If you want links to the next and previous pages on a singular page created with <!--nextpage--> then you're using the wrong function.
get_next_posts_page_link(), as suggested by the name, is for getting the next page of posts and is intended for use on archives.
To add the pagination links to a singular page, use wp_link_pages(), and use it inside the loop.
while (have_posts()) : the_post();
the_content();
wp_link_pages();
endwhile;
By default it outputs page numbers, but if you want "Next" and "Previous" links, set the next_or_number argument to next:
while (have_posts()) : the_post();
the_content();
wp_link_pages( array(
'next_or_number' => 'next',
) );
endwhile;
See the documentation for more options for customising the output.
Using get_next_posts_page_link function to get url of paginated post's next page url, but it's adding directories to it that simply do not exist.
Here is the code where I use it and probably missing something somewhere
while (have_posts()) : the_post();
the_content();
endwhile;
// echoing to see the actual url it would bring up if used in an anchor
echo get_next_posts_page_link();
And here are the urls
On page 1: mysitedomain/paginatedpage/page/2/ instead of mysitedomain/paginatedpage/2/
On page 2: mysitedomain/paginatedpage/2/page/2/ instead of mysitedomain/paginatedpage/3/
On page 3: mysitedomain/paginatedpage/3/page/2/ instead of mysitedomain/paginatedpage/4/
And so on...
Using get_next_posts_page_link function to get url of paginated post's next page url, but it's adding directories to it that simply do not exist.
Here is the code where I use it and probably missing something somewhere
while (have_posts()) : the_post();
the_content();
endwhile;
// echoing to see the actual url it would bring up if used in an anchor
echo get_next_posts_page_link();
And here are the urls
On page 1: mysitedomain/paginatedpage/page/2/ instead of mysitedomain/paginatedpage/2/
On page 2: mysitedomain/paginatedpage/2/page/2/ instead of mysitedomain/paginatedpage/3/
On page 3: mysitedomain/paginatedpage/3/page/2/ instead of mysitedomain/paginatedpage/4/
And so on...
Share Improve this question asked Nov 21, 2018 at 23:39 KunzhutKunzhut 32 bronze badges 4- in what file are you using that function? – Michael Commented Nov 21, 2018 at 23:54
- custom page template – Kunzhut Commented Nov 22, 2018 at 0:04
-
1
Archive pagination is
/page/n/, singular post/page pagination is/n/. You say this is on a custom page template, which would indicate that this is a singular view and not an archive view, but your loop seems to indicate otherwise. Clarification is required here. – Milo Commented Nov 22, 2018 at 0:25 - I'm talking about paginating by <!--nextpage--> – Kunzhut Commented Nov 22, 2018 at 3:20
1 Answer
Reset to default 0If you want links to the next and previous pages on a singular page created with <!--nextpage--> then you're using the wrong function.
get_next_posts_page_link(), as suggested by the name, is for getting the next page of posts and is intended for use on archives.
To add the pagination links to a singular page, use wp_link_pages(), and use it inside the loop.
while (have_posts()) : the_post();
the_content();
wp_link_pages();
endwhile;
By default it outputs page numbers, but if you want "Next" and "Previous" links, set the next_or_number argument to next:
while (have_posts()) : the_post();
the_content();
wp_link_pages( array(
'next_or_number' => 'next',
) );
endwhile;
See the documentation for more options for customising the output.
本文标签: paginationgetnextpostspagelink adds Inexistent directories
版权声明:本文标题:pagination - get_next_posts_page_link adds Inexistent directories 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749160956a2325384.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


/page/n/, singular post/page pagination is/n/. You say this is on a custom page template, which would indicate that this is a singular view and not an archive view, but your loop seems to indicate otherwise. Clarification is required here. – Milo Commented Nov 22, 2018 at 0:25