curtiscde / hugo-theme-massively

Massively theme for Hugo static site generator
https://hugo-theme-massively.netlify.app
Other
155 stars 138 forks source link

Activating the 'Active' Class Based On The Current URL (Page2,Page3 Etc) #92

Open WillNaylor1994 opened 4 years ago

WillNaylor1994 commented 4 years ago

Hi All!

I have been developing my blog using this theme and have added a fair few amendments to make it work for me. These include:

This means when you click on an option in the nav bar (or just click 'next' or 'previous') the nav bar will have the correct option highlighted for which page you're on.

It was just this line of jQuery to add in 'jquery.min.js'

$(document).ready(function() {var pathname = window.location.pathname;$('.links > li > a[href="'+pathname+'"]').parent().addClass('active');})

I thought i should add this here as this took me a while to figure out and could save people a lot of time!

Working example > www.billiewillytravel.co.uk

RuifMaxx commented 3 years ago

thank you a lot

schmidde97 commented 3 years ago

Does this still work? Could not get that to work. I added the above code to 'jquery.min.js' in the theme folder.

WillNaylor1994 commented 3 years ago

Does this still work? Could not get that to work. I added the above code to 'jquery.min.js' in the theme folder.

Hi! This is still working for my site, as you can see from the example website above.

Depending on which page you're on (page1,page2 etc) the 'active' class is assinged to the correct nav bar item which makes the colours reverse.

I added the code above at the end of the 'jquery.min.js' file and it worked for me.

Maybe just double check that your class for the nav bar is also called 'active'. Perhaps this has been changed with future updates, i am not too sure.

schmidde97 commented 3 years ago

thanks!

one other question: how did you get the posts organized on the different pages? I tried with _index.md & taxonomy, but that gives me only a blank page...