Forum

Thread tagged as: Question

Link to subpage

I have several subpages of news.php: news1.php, news2.php etc. How can I set a link eg. in the index-file to the first subpage? The subpages are created with perch navigation, so the name of the first subpage might change... Thanks a lot!

Martin Stettler

Martin Stettler 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you should be able to do that using from-path in the navigation options.

What do I have to add here to output just the first subpage-link? Thanks for your help, Drew.

<?php perch_pages_navigation(array(
     'from-path' => '/news',
     'template'  => 'news.html'
)); ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

I was going to suggest 'count' => 1 but it looks like that's not actually implemented.

Next best option might be to wrap your template output in

<perch:if exists="perch_item_first">
...
</perch:if>

Unfortunately it's not working...

Drew McLellan

Drew McLellan 2638 points
Perch Support

What happens?

The same. For me logic, we just ask if the first item exists, we would need a consequence then. How can we just output the first page?

Drew McLellan

Drew McLellan 2638 points
Perch Support

"The same" is obviously easily apparent for you to see, but I have no idea what that means. If I'm going to be able to be of any help, you need to describe what you're seeing, what changes you've made to the template and options, and what result you're getting.

Remember that I have no knowledge of your project or what you're trying to achieve.

Of course, sorry! Look what we have actually:

<?php perch_pages_navigation(array(
    'from-path' => '/news',
    'template'  => 'news.html',
)); ?>

That gives the following output of course:

<a href=“/news1.php”>News 1</a><a href="/news2.php”>News 2</a>

and so on...

So now my question is: what do I have to add that it outputs just the first a-tag? If I add the «if exists» condition the output remains the same. Many thanks!

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you tried perch_pages_next_page() ?

This shows the parent page, not the second level. And if I add

'levels' => 1

it still does not works...

Drew McLellan

Drew McLellan 2638 points
Perch Support

The level option controls the number of levels to show.

Does adding in the from-path option step you down a level?

So, the following shows the parent page:

<?php perch_pages_next_page(array(
    'from-path' => '/news',
    'levels' => 1,
    'template'  => 'news.html',
 )); ?>

and this shows all of subpages:

<?php perch_pages_navigation(array(
     'from-path' => '/news',
     'levels' => 1,
     'template'  => 'news.html',
 )); ?>

Maybe my from-path is wrong? The navigation structure in Perch looks like this:

1. news.php
    1.1. news1.php
    1.2. news2.php

and so on

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't see why texting for the first item only wouldn't work. Can you should me what you did with your template when that failed?

I agree, the solution should be perch_pages_next_page(). I think my from-path is wrong, because even without it I have the parent page as output. How does from-path have to be? The parent page of subpages is news.php, the path of a subpage is eg. news1.php. Is this correct?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are the news items not within a subfolder?

Yes they are. The from-path inside perch_pages_next_page() does not seem to work. It always outputs a link at the same level and not inside the news-folder. Sorry, Drew this seems to be strange...

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, it's perch_pages_navigation() that you want with the template modification I suggested.

But to link to the first element in the subfolder /news I still think perch_pages_next_page() would be fine. Otherwise I get the whole navigation. This could only be the solution if we have a condition to just show the first element. But as you wrote in an answer before count is not suppported... Would there be another way to achieve this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you think perch_pages_next_page() will be fine then you stick with that.

I think it sounds like you're very close with perch_pages_navigation() and just need to modify the template, but what do I know.

Thank you very much for your help anyway, Drew! I keep on finding the solution...