Forum

Thread tagged as: Question

Previous/Next links

Hi guys!

I have the following subnavigation:

<ul>
    <li>
        <a href="#">Home</a>
            <?php 
                perch_pages_navigation(array(
                    'from-path' => '/index',
                    'levels'    => 0
                    ));
            ?>
    </li>
    <li><a href="page2.php">Page 2</a></li>
    <li><a href="page3.php">Page 3</a></li>
</ul>

The home subnavigation has several pages. I want to set links for previous/next pages in the content of these pages. Can you please tell me what is wrong with the following code?

<a href="<perch:page id="prev_url" type="hidden" encode="false" />">Previous</a>
<a href="<perch:page id="next_url" type="hidden" encode="false" />">Next</a>

Thanks a lot!

Martin Stettler

Martin Stettler 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The navigation functions don't currently offer any pagination.

Ok. Is there any other way to build this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What are you trying to achieve?

The home-navigation has several subpages. I want to put on each of them a prev and next link to navigate directly from the bottom of every page through all subpages. The subnavigation itself is set to invisible.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I would have thought you could use perch_pages_next_page() and perch_pages_previous_page() for that.

https://docs.grabaperch.com/docs/navigation/perch-pages-previous-page/ https://docs.grabaperch.com/docs/navigation/perch-pages-next-page/

Adding this to the href-tag actually does not work. Maybe there is a problem with the navigation, too. It looks like this:

<ul>
    <li>
        <a href="#">Home</a>
            <?php 
                perch_pages_navigation(array(
                    'from-path'=>'*',
                    ));
            ?>
    </li>
    <li><a href="page2.php">Page 2</a></li>
    <li><a href="page3.php">Page 3</a></li>
</ul>

Only the subnavigation should be editable. The index.php file shows correctly the subnavigation tree. But within the subpages I can't find it any more. Though it is implemented the same way. What could be wrong? Many thanks!

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show us the code you're using?

The output in the page view is still weird, but it jumps now to the correct subpage. Here's the a-tag for the next page:

<a href="<?php 
    perch_pages_next_page(array(
        'hide-extensions'  => false,
        'hide-default-doc' => true,
        'template'         => 'custom.html',
        'skip-template'    => false
    ));
?>">
</a>

I see the page name and this: "> Any idea?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me the HTML output?

Ok, not good. Here's the whole navigation... How can we extract the url?

<a href="<ul class="custom">
    <li>
        <a href="/test-2.php">
            Test 2
        </a>

    </li>
</ul>">next</a>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Does custom.html output HTML, or just the URL to the page?

The output is HTML:

<ul class="custom">
    <li>
        <a href="/test-1.php">
            Test 1
        </a>

    </li>

    <li>
        <a href="/test-2.php">
            Test 2
        </a>

    </li>
</ul>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so it wouldn't make sense to inject that result into the href attribute of a link. You need to either change the template you're using, or change how you're outputting the link.

I've tried some different things now, nothing good. Do you have an idea how this could be solved? Any help is much appreciated!

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is the link that's being output correct? What problem are you experiencing?

I could finally solve it. Using perch_pages_next_page() and perch_pages_previous_page() is fine. I put them inside divs and styled a custom navigation template. Thanks for your help, Drew!