Jump to content

How to make jekyll navbar show active on multiple pages

Thingyman

I'm making a website using jekyll, and I have a navbar set up and one of my pages is a blog. When I am on the blog, the navbar is normal and shows that you are on the blog. But on any of the posts, instead of showing you are in the blog, it shows that you are nowhere on the navbar. How can I fix this?

 

My blog.html

---
layout: default
title: Blog
description: Blog
---

<h1>Latest Posts</h1>

<ul>
  {% for post in site.posts %}
    <li>
      <h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
      {{ post.excerpt }}
    </li>
  {% endfor %}
</ul>

 

My navbar

<div class="nav">
  <img src="/assets/images/Favicon.png" /><span><h1>Thingyman</h1></span>
  {% for item in site.data.navigation.items %}
  <a href="{{ site.baseurl }}{{ item.link }}" {% if page.url == item.url %}class="active" {% endif %}>
    {{ item.name }}
  </a>
{% endfor %}
</div>

 

image.thumb.png.3202437614f234432e6c63bc5bf827e2.png

image.thumb.png.c97a9210a46f4902a9cb29092b64685e.png

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×