Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
WillNaylor1994 opened this issue Sep 13, 2020 · 4 comments

Comments

@WillNaylor1994
Copy link

WillNaylor1994 commented Sep 13, 2020

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:

  • Making the pagination sort ByDate across all pages.

  • Adding jQuery to assign the 'Active' class in the nav bar to whichever page you're on.

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
Copy link
Contributor

thank you a lot

@schmidde97
Copy link

schmidde97 commented May 7, 2021

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

@WillNaylor1994
Copy link
Author

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
Copy link

schmidde97 commented May 8, 2021

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants