pages - Start post pagination at 0 instead of 1

admin2025-01-07  4

Is it possible to start post pagination count at zero instead of 1? I want the URLs to be like this:

../page (Foreword)

../page/1 (Chapter 1)

../page/2 (Chapter 2)

But by default the URL is not corresponding to my chapter numbers:

../page (Foreword)

../page/2 (Chapter 1)

../page/3 (Chapter 2)

Is it possible to start post pagination count at zero instead of 1? I want the URLs to be like this:

../page (Foreword)

../page/1 (Chapter 1)

../page/2 (Chapter 2)

But by default the URL is not corresponding to my chapter numbers:

../page (Foreword)

../page/2 (Chapter 1)

../page/3 (Chapter 2)

Share Improve this question edited Jun 15, 2020 at 8:21 CommunityBot 1 asked Aug 7, 2014 at 11:06 JorikJorik 93 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 0

The ../page/X structure ties to pagination, not to post names. I'm sure you could change them but I'm not sure how deep the effects of the change would be.

Have you thought about an alternate solution?

Name each post your chapter name

  • Forward
  • Chapter 1
  • Chapter 2

Add a plugin that adds previous / next navigation functionality each individual post. Something like WP Post Navigation. That way, when someone finishes reading the first chapter, there will be a link to navigate to the next.

You could change your url structure to fit your needs. For example, if you wanted the structure to look like http://yoursite.com/forward, http://yoursite.com/chapter-1, etc. you'd just have to change the permalink settings to 'post name' (Admin > Settings > Permalinks).

it is possible to start post pagination count at zero instead of 1 in WP. You can achieve this by customizing the pagination links generated by Wordpress

add code below your functions.php file

function custom_pagination_rewrite_rules($rules) {
    $new_rules = array(
        'page/0?$' => 'index.php?paged=0',
        'page/(\d+)/?$' => 'index.php?paged=$matches[1]'
    );
    return $new_rules + $rules;
}
add_filter('rewrite_rules_array', 'custom_pagination_rewrite_rules');


function custom_pagination_paged($paged) {
    if (get_query_var('paged') == 0) {
        return 0;
    } else {
        return $paged;
    }
}
add_filter('get_query_var_paged', 'custom_pagination_paged');

I have the same problem too. The only solution I could find is to put the foreword/introduction and chapter one in the first part, then press ALT+SHIFT+P to start the pagination.

This ensured that page 2 has chapter 2.

The problem with this solution is that page 1 is very very long.

If you type in the address page/0, you will go to the main page: page/

I am sure I have seen sites that start pagination at "0", and "0" even appears in the pagination, but I can't find any source to explain how to do so.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736254929a244.html

最新回复(0)