Forum

Thread tagged as: Question, Blog

How to make menu show blog posts as "current" page

I have a basic menu for the main pages in my site. One item in it is a "News" page for our blog, e.g. /blog/index.php, which also contains an editable region for a paragraph of content above the list of blog posts and the list of categories. The menu templates pick it up and apply my current-page style to the list item for "News".

However when I'm on blog/archive.php or blog/post.php it obviously won't do that, but I'd like it to. Those pages are part of the News section of the site and I'd like to indicate that visually.

I've tried using if-exists for ancestor pages but since the blog app doesn't use a sub-item structure it doesn't work (and I'm not sure it'd be appropriate anyway). I've also tried using a value match and that didn't work either. Is there some obvious way to do this that I've missed?

I currently have this, with the first current-page style working for all menu items:

<a href="<perch:pages id="pagePath" />"
  <perch:if exists="current_page"> aria-current="page"</perch:if>
  <perch:if id="pagePath" value="blog" matches="contains"> class="section"</perch:if>
>

Folder structure:

- index.php
- resources.php
- services.php
- blog
  -- index.php (shows as News in menu)
  -- post.php
  -- archive.php
Julie Grundy

Julie Grundy 0 points

  • 3 years ago
Simon Clay

Simon Clay 127 points

Hi Julie,

You'll need to add Post and Archive into the pages list, (as sub pages of News). Although they won't have an 'editable' content, Perch will need to know they're there. Perch can then give them the ancestor/child classes for you to target.

Thankyou Simon, that worked perfectly. I knew it would be something basic that I'd overlooked!

For future reference, when I created the pages in the admin, I had to edit the Path field in the Page > Location section. A default URL was created but obviously for this to work it needs "/blog/archive.php" or "/blog/post.php" or any other similar pages to be in that part.