Add class to menu item.

Post Reply
xanmean
Jr. Bludit
Posts: 5
Joined: Tue Jan 29, 2019 7:14 pm

I want add class="active" to current static page.
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

The theme Keep It Simple gives you an example:

https://github.com/bludit-themes/keep-i ... ar.php#L29
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
Tim
Jr. Bludit
Posts: 4
Joined: Tue May 19, 2020 9:56 am
Location: Minsk
Contact:

Edi wrote: Tue Jan 29, 2019 7:54 pm The theme Keep It Simple gives you an example:

https://github.com/bludit-themes/keep-i ... ar.php#L29
I'm also looking for a solution. I downloaded the theme, but it doesn't work, class='current' does not apply to the current page
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

Have you defined a CSS class "current"?
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
Tim
Jr. Bludit
Posts: 4
Joined: Tue May 19, 2020 9:56 am
Location: Minsk
Contact:

Edi wrote: Tue May 19, 2020 11:24 am Have you defined a CSS class "current"?
Yes, I'm porting a wordpress theme, all classes exist.
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

Is there a link to the installation?
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
Tim
Jr. Bludit
Posts: 4
Joined: Tue May 19, 2020 9:56 am
Location: Minsk
Contact:

Edi wrote: Tue May 19, 2020 11:50 am Is there a link to the installation?
http://bludit.eu5.net/

Code: Select all

        <!-- Static pages -->
        <?php
        $current_page = $_SERVER['REQUEST_URI'];
        foreach ($staticContent as $staticPage) : ?>

          <li <?php if ($current_page == '/' . $staticPage->slug()) echo 'class="current-menu-item"'; ?>>
            <a href="<?php echo $staticPage->permalink(); ?>"><?php echo $staticPage->title(); ?></a>
          </li>

        <?php endforeach ?>
User avatar
Tim
Jr. Bludit
Posts: 4
Joined: Tue May 19, 2020 9:56 am
Location: Minsk
Contact:

funny, it works correctly on hosting, but it doesn't work on the local server
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

Perhaps a problem with the settings of the path.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
Post Reply