Navigation Issue on Blog Posts
On my webite I have the navigation dropdown working but as soon as I go onto the post pagee of the blog the drop down does not seem to work. This is the code that I have throughout the website. This is on the posts.php
<?php
perch_pages_navigation(
array(
'from-path' => '/',
'levels' => 0,
'hide-extensions' => true,
'template' => array('item.html', 'items.html')
)
);
?>
items.html
<perch:before>
<ul class="nav navbar-nav">
</perch:before>
<li class="<perch:if exists="current_page">active </perch:if><perch:if exists="subitems">dropdown</perch:if>"<perch:if exists="ancestor_page"> class="ancestor"</perch:if>>
<a <perch:if exists="subitems">class="dropdown-toggle" data-toggle="dropdown"</perch:if> href="<perch:pages id="pagePath" />">
<perch:pages id="pageNavText" /> <perch:if exists="subitems"></perch:if>
</a>
<perch:pages id="subitems" encode="false" />
</li>
<perch:after>
</ul>
</perch:after>
items.html
perch:before>
<ul class="dropdown-menu">
</perch:before>
<li<perch:if exists="current_page"> class="active"</perch:if><perch:if exists="ancestor_page"> class="ancestor"</perch:if>>
<a href="<perch:pages id="pagePath" />">
<perch:pages id="pageNavText" />
</a>
<perch:pages id="subitems" encode="false" />
</li>
<perch:after>
</ul>
</perch:after>
I maybe something simple that I have not included.
I also noticed I now have a services folder? Shall I copy my subpages into that folder?
Have those pages been added to the site structure?
Yes the pages are in the public_html. Do I need to add them to the services folder, and would I need to alter anything. It only seems to not work on the post.php page which is located in the blog folder in public_httml
Have you added them to the Perch representation of the site structure? Are they there in your Pages list? If not, Perch doesn't know about them and they won't appear in the navigation.
Yes they are in the pages backend of perch
Would I need to create a subfolder as I have a services folder but when I add it as a subpage it says it does not exist. Where would I need to put this and how should my code work?
What is the precise error you're getting, and what are the steps to reproduce it?
The error is that the drop down menu is not working on the blog posts page. I have the same navigation throughout my site. It works on every page except that.
I've tried adding the pages that are in the drop down to a folder in public html and then in perch tell it that there is a sub folder with the page in but it says the subfolder is not there. I also copied the file into that folder to match perch changing the runtime and it still won't work.
What is the precise error you're getting?
It says the subfolder does not exist. But it's definitely there
The main error when I go onto my blog posts and then try and select the my services drop down from the list it says The requested URL /my-services was not found on this server.
I added the drop down through Perch using Add a New Page. I then chose Page Already Exists or is a link only as there is no services page its just a link for the drop down menu.
If there isn't a page there you will get a 404.
You've asked Perch to add a link to a page that doesn't exist, if you click that link you get a 404. This seems like expected behaviour.
That functionality is to let Perch know about pages that exist (perhaps you created it manually and not through Perch). So Perch is just doing exactly what you told it to - creating a link to a page.
But it works on every page except the posts page. Its not designed to be a page rather just a link to a drop down menu. Its only on the posts page that it does not seem to follow the navigation which is the code above which I have copied to all my pages. Could there be an error in the code at the top? Would it be easier to show you a live example :
www.robertbroley.co.uk.
I know that I changed the urls using the clean url method and changed the slug and htaccess. Could there be an error when changing that?
I don't see any 404s on that site.
On this page: https://www.robertbroley.co.uk/blog/test
The "My Services" link?
Yes that it. If you try another page then select my services the dropdown work but then it does not work on the posts page.
Your JavaScript isn't loading on that page because it's been including using a page-relative path.
Thanks for that Drew. I will alter the file structure. And see what happens.
Yes, that's the issue. If you view source on your page you'll see that Perch is generating the HTML for your drop down. If you look in your browser console, you'll see that your JavaScript links are throwing errors. This is very basic stuff, nothing to do with Perch.
Change:
to: