admin管理员组文章数量:1389750
I have a menu item where a CSS class is added with a 'page_active' class (which visually shows an underline under the relevant item). This is added on certain menu items if the is_page('Latest')
or is_archive('sites)
conditions return true.
One of my main menu items (menu-item-3) is a custom taxonomy so instead of using either of the above two methods, I'm using is_tax('web')
for a custom taxonomy called 'web'. This isn't adding the 'page_active' class though and also the CSS class is still being added to one of the other two items.
Below is the code - any ideas about how to solve this would be hugely appreciated.
CSS
.underline.page_active:after {
content: '';
position: absolute;
width: 100%;
height: 5px;
background: #a882ff;
left: 0;
bottom: -0.39em;
z-index: -1;
}
.menu-item-2.underline.page_active:after {
width: 3.1rem;
left: 5.7rem;
z-index: -1;
bottom: 2rem;
}
HTML / PHP
<ul class="nav-menu-items">
<li class="menu-item menu-item-1"><a class="td nav-link underline <?php if (is_page('Latest')) {echo "page_active";};?>" title="Latest" href="<?php echo esc_url(home_url( '/' ));?>">Latest</a></li>
<li class="menu-item menu-item-2 underline <?php if (is_archive('sites') || is_tax('graphic-design')){echo "page_active";}; ?>">Design
<ul class="submenu design-submenu">
<li class="submenu-item submenu-item-1"><a title="Sites We Like" class="td nav-link" href="<?php echo esc_url(home_url('/sites'));?>">Sites We Like</a></li>
<li class="submenu-item submenu-item-2"><a title="Graphic Design" class="td nav-link" href="<?php echo esc_url(home_url('/news_categories/graphic-design'));?>">Graphic Design</a></li>
</ul>
</li>
<li class="menu-item menu-item-3"><a title="Web" class="td nav-link underline <?php if (is_tax('web')){echo "page_active";};?>" href="<?php echo esc_url(home_url('/news_categories/web'));?>">Web</a></li>
<li class="menu-item menu-item-4"><a title="Marketing" class="td nav-link underline" href="<?php echo esc_url(home_url('/news_categories/marketing'));?>">Marketing</a></li>
</ul>
I have a menu item where a CSS class is added with a 'page_active' class (which visually shows an underline under the relevant item). This is added on certain menu items if the is_page('Latest')
or is_archive('sites)
conditions return true.
One of my main menu items (menu-item-3) is a custom taxonomy so instead of using either of the above two methods, I'm using is_tax('web')
for a custom taxonomy called 'web'. This isn't adding the 'page_active' class though and also the CSS class is still being added to one of the other two items.
Below is the code - any ideas about how to solve this would be hugely appreciated.
CSS
.underline.page_active:after {
content: '';
position: absolute;
width: 100%;
height: 5px;
background: #a882ff;
left: 0;
bottom: -0.39em;
z-index: -1;
}
.menu-item-2.underline.page_active:after {
width: 3.1rem;
left: 5.7rem;
z-index: -1;
bottom: 2rem;
}
HTML / PHP
<ul class="nav-menu-items">
<li class="menu-item menu-item-1"><a class="td nav-link underline <?php if (is_page('Latest')) {echo "page_active";};?>" title="Latest" href="<?php echo esc_url(home_url( '/' ));?>">Latest</a></li>
<li class="menu-item menu-item-2 underline <?php if (is_archive('sites') || is_tax('graphic-design')){echo "page_active";}; ?>">Design
<ul class="submenu design-submenu">
<li class="submenu-item submenu-item-1"><a title="Sites We Like" class="td nav-link" href="<?php echo esc_url(home_url('/sites'));?>">Sites We Like</a></li>
<li class="submenu-item submenu-item-2"><a title="Graphic Design" class="td nav-link" href="<?php echo esc_url(home_url('/news_categories/graphic-design'));?>">Graphic Design</a></li>
</ul>
</li>
<li class="menu-item menu-item-3"><a title="Web" class="td nav-link underline <?php if (is_tax('web')){echo "page_active";};?>" href="<?php echo esc_url(home_url('/news_categories/web'));?>">Web</a></li>
<li class="menu-item menu-item-4"><a title="Marketing" class="td nav-link underline" href="<?php echo esc_url(home_url('/news_categories/marketing'));?>">Marketing</a></li>
</ul>
Share
Improve this question
asked Feb 21, 2020 at 15:39
pjk_okpjk_ok
9082 gold badges15 silver badges36 bronze badges
6
|
Show 1 more comment
1 Answer
Reset to default 0I found the solution to this, the is_tax();
method needs two arguments - the taxonomy and the term itself, so it should have been:
is_tax('news_categories', 'web')
Just as an extra point the is_archive('sites')
should also have been is_post_type_archive('sites')
本文标签: navigationistax() conditional tag not working
版权声明:本文标题:navigation - is_tax() conditional tag not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744721009a2621694.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
is_tax
only works if you're accessing archive page of web taxonomy. Are you? – Cadu De Castro Alves Commented Feb 21, 2020 at 18:07global $wp_query
and thenvar_dump($wp_query)
, you should be able to see if$wp_query->is_tax
is properly set. – Cadu De Castro Alves Commented Feb 21, 2020 at 18:44<?php ?>
tags on the taxonomy archive template file? Or in theheader.php
file where the nav menu is? – pjk_ok Commented Feb 21, 2020 at 18:53web
is actually a term? – majick Commented Feb 23, 2020 at 2:19