Add class to menu item.

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

Tue Jan 29, 2019 7:23 pm

I want add class="active" to current static page.
User avatar
Edi
Site Admin
Posts: 1927
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

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
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
User avatar
Tim
Jr. Bludit
Posts: 4
Joined: Tue May 19, 2020 9:56 am
Location: Minsk
Contact:

Tue May 19, 2020 9:59 am

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: 1927
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

Tue May 19, 2020 11:24 am

Have you defined a CSS class "current"?
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
User avatar
Tim
Jr. Bludit
Posts: 4
Joined: Tue May 19, 2020 9:56 am
Location: Minsk
Contact:

Tue May 19, 2020 11:34 am

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: 1927
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

Tue May 19, 2020 11:50 am

Is there a link to the installation?
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
User avatar
Tim
Jr. Bludit
Posts: 4
Joined: Tue May 19, 2020 9:56 am
Location: Minsk
Contact:

Tue May 19, 2020 1:39 pm

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:

Tue May 19, 2020 9:47 pm

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

Tue May 19, 2020 11:38 pm

Perhaps a problem with the settings of the path.
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
Post Reply