Page 1 of 1

Add class to menu item.

Posted: Tue Jan 29, 2019 7:23 pm
by xanmean
I want add class="active" to current static page.

Re: Add class to menu item.

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

https://github.com/bludit-themes/keep-i ... ar.php#L29

Re: Add class to menu item.

Posted: Tue May 19, 2020 9:59 am
by Tim
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

Re: Add class to menu item.

Posted: Tue May 19, 2020 11:24 am
by Edi
Have you defined a CSS class "current"?

Re: Add class to menu item.

Posted: Tue May 19, 2020 11:34 am
by Tim
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.

Re: Add class to menu item.

Posted: Tue May 19, 2020 11:50 am
by Edi
Is there a link to the installation?

Re: Add class to menu item.

Posted: Tue May 19, 2020 1:39 pm
by Tim
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 ?>

Re: Add class to menu item.

Posted: Tue May 19, 2020 9:47 pm
by Tim
funny, it works correctly on hosting, but it doesn't work on the local server

Re: Add class to menu item.

Posted: Tue May 19, 2020 11:38 pm
by Edi
Perhaps a problem with the settings of the path.