Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Creating a header menu link to show all post in a specific category. How?

Solved by pamtbaau View solution

Started by Dorian Jepsen 3 years ago · 8 replies · 353 views
3 years ago

My demo site is here.

The header menu has links for Flights, Maintenance, and Stuff. Those links were created by making folders (directories) located at...

/public_html/user/pages/02.flights/
/public_html/user/pages/03.maintenance/
/public_html/user/pages/04.stuff/

and inside each folder was a default.md file with the following code...

YAML
---
redirect: '/category:flights'
---
YAML
---
redirect: '/category:maintenance'
---
YAML
---
redirect: '/category:stuff'
---

My question: Is this to proper way to be creating header links to display category pages? I'm guessing there's a more elegant way to do this, but I can't figure it out.

3 years ago

@Alpha, Have you considered using the TaxonomyList plugin which is used by the Blog Site skeleton? See Popular Tags in the sidebar.

If you have, why did you dismiss its use and opt for menu items?

3 years ago

I've only got three categories for all my posts and I have always preferred navigating a site via a header menu (because headers always display at the top before sidebars) so I was trying my best to replicate the format that's on the site I'm trying to update.

3 years ago Solution

@Alpha, It is however very common for blog sites to show a category list, or a category cloud. Visitors are familiar with the concept...

But if you wish to stick to the menu items, you could alternatively, instead of using redirects, which might hurt your SEO if not used correctly and cause an extra roundtrip by the browser, consider turning each default.md page into a blog.md page, each with a proper collection.

For example: /public_html/user/pages/02.flights/blog.md

YAML
content:
  items:
    '@taxonomy.category': flights
3 years ago

@Alpha, Your page header is incorrect... Add the opening and closing ---.

You will probably also need to add other header info like pagination, hero-image, etc. See the Blog Site skeleton.

3 years ago

I added sorting and pagination, but it's not working. It's loading every post and ordering them randomly. Any ideas?

YAML

---
content:
  items:
    '@taxonomy.category': flights
    order:
        by: date
        dir: desc
    limit: 10
    pagination: true
---```
3 years ago

Disregard. My tab spaces were messed up. This works.

YAML
---
content:
  items:
    '@taxonomy.category': flights
  order:
    by: date
    dir: desc
  limit: 10
  pagination: true
---

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 76 8 hours ago
General · by pamtbaau, 13 hours ago
1 47 12 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago