Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit prev/next_page to specific content/dir #634

Closed
digitalinferno opened this issue May 10, 2022 · 3 comments
Closed

limit prev/next_page to specific content/dir #634

digitalinferno opened this issue May 10, 2022 · 3 comments

Comments

@digitalinferno
Copy link

When we use the next_page / prev_page code it returns the next/prev page as specified by the config.yml configuration file
If we have

content/blog
- page a
- page c
content/foo
- page b

then the alpha order is

- blog/page a
- foo/page b
- blog/page c

But for me it make no sense to have this order if I would navigate only the blog content (similar issue if we use the date sort).

So another level of configuration is needed, my 2 cents.
pages_order_by: meta/alpha/date/subdir

In twig is something like this:

            {% set next_this = '' %}
            {% set prev_this = '' %}
            {% set n = '' %}
            {% set p = '' %}
            
            {% for page in pages(mysubdir)|sort_by(date)|reverse %}
                {% if current_page.id == page.id %}
                    {% set n = (loop.index-1) %}
                    {% set p = (loop.index+1) %}
                {% endif %}
            {% endfor %}   
            
            {% for page in pages(mysubdir)|sort_by(date)|reverse %}
                {% if n == loop.index %}
                    {% set next_this = page %}
                {% endif %}
                {% if p == loop.index %}
                    {% set prev_this = page %}
                {% endif %}  
            {% endfor %} 
         
            «{{ next_this.title}} ... {{ prev_this.title}}»
@digitalinferno
Copy link
Author

@PhrozenByte it is an improvement request rather than a support request

@PhrozenByte
Copy link
Collaborator

Alpha order is going to be blog/page a, blog/page c and foo/page b, as pages aren't just sorted by their basename, but the full path. If you want it to roll over at the directory boundary, use the pages() function and sort_by filter (as you did, even though you don't need two iterations). pages_order is for the global page order. Directories don't have any special meaning in Pico on purpose, as we want users to organize their pages how they prefer.

See #615 for an extensive discussion about this and various Twig snippets

@digitalinferno
Copy link
Author

Thank you, I have totally missed this discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants