我已经创建了一个菜单(导航栏),它被放置在标题的副本中。下面我的孩子主题中的php文件:
<?php wp_nav_menu( array( \'container_class\' => \'menu-header\', \'theme_location\' => \'primary\',\'container\' => \'\' ) ); ?>
它工作得很好,只是活动的选定菜单项的CSS除了“主页”之外不适用于所有内容。
这会在选中“主页”时更改背景,但不会更改其他顶部菜单项。
#access ul li.current_page_item > a, #access ul li.current-menu-ancestor > a, #access ul li.current-menu-item > a, #access li.selected > a, #access ul li.current-menu-parent > a, #access ul li.current_page_item, #access ul li.current-menu-item, #access li.selected {
background-color: #1E0D51 !important;
}
所有CSS都会显示为悬停。
我花了几个小时在这个问题上,不知道是什么问题。
非常感谢您的任何见解或想法。
ThanksTim公司
放入收割台。php之后<?php wp_nav_menu( array( \'container_class\' => \'menu-header\', \'theme_location\' => \'primary\',\'container\' => \'\' ) ); ?>
<ul>
<?php if ( is_user_logged_in() ) { ?>
<li class="menu-item"id="menu-item-22"> <a href="<?php echo bp_loggedin_user_domain() ?>activity/just-me/">My Wall</a>
<ul class="sub-menu">
<li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ? >activity/friends/">My Friends\' Activities</a></li>
<li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ? >profile/edit/group/1">Edit My Profile</a></li>
</ul>
</li>
<!-- new menu here edit the links-->
<li class="menu-item"id="menu-item-22"> <a href="http://maolalumnet.org/members/">All Members</a>
<ul class="sub-menu">
<li class="menu-item"> </li>
</ul>
</li>
<!--end menu--->
<!-- new menu here edit the links-->
<li class="menu-item"id="menu-item-22"> <a href="http://maolalumnet.org/groups/">All Groups</a>
<ul class="sub-menu">
<li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?>groups/">My Groups</a></li>
</ul>
</li>
<!--end menu--->
<!-- new menu here edit the links-->
<li class="menu-item"id="menu-item-22"> <a href="http://maolalumnet.org/events/">All Events</a>
<ul class="sub-menu">
<li class="menu-item"> <a href="http://maolalumnet.org/events-calander/">Calendar View</a></li>
<li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?>events/my-events/">My Events</a></li>
<li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?>events/my-events/">Create an Event</a></li>
</ul>
</li>
<!--end menu--->
<?php ;} ?>
最合适的回答,由SO网友:xyz 整理而成
我忘了加上这是BUDDYPRESS
这起到了作用:
添加到函数。php:
//--Current Page URL
function curPageURL() {
$pageURL = \'http\';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
添加到标题。php之前
</header>
<?php
if ( curPageURL() == bp_loggedin_user_domain().\'activity/just-me/\') { $current = \'one\'; }
elseif ( curPageURL() == bp_loggedin_user_domain().\'activity/friends/\') { $current = \'one\'; }
elseif ( curPageURL() == bp_loggedin_user_domain().\'profile/edit/group/1\') { $current = \'one\'; }
elseif ( curPageURL() == \'http://my_site.com/members/\') { $current = \'two\'; }
elseif ( curPageURL() == \'http://my_site.com/groups/\'){ $current = \'three\'; }
elseif ( curPageURL() == bp_loggedin_user_domain().\'groups/\') { $current = \'three\'; }
elseif ( curPageURL() == \'http://my_site.com/events/\') { $current = \'four\'; }
elseif ( curPageURL() == bp_loggedin_user_domain().\'events/my-events/\') { $current = \'four\';}
?>
<style type="text/css">
#<?php echo $current; ?> {
background-color: #1E0D51;
font-family: Comic Sans MS,Comic Sans MS5,cursive;
} }
</style>
原始代码已略微更改为:
<ul>
<li class="menu-item"id="one"> <a href="<?php echo bp_loggedin_user_domain() ?>activity/just-me/">My Wall</a>
<ul class="sub-menu">
<li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?>activity/friends/">My Friends\' Activities</a></li>
<li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?>profile/edit/group/1">Edit My Profile</a></li>
</ul>
</li>
<!-- new menu here edit the links-->
<li class="menu-item"id="two"> <a href="http://my_site.com/members/">All Members</a>
<ul class="sub-menu">
<li class="menu-item"> </li>
</ul>
</li>
<!--end menu--->
<!-- new menu here edit the links-->
<li class="menu-item"id="three"> <a href="http://my_site.com/groups/">All Groups</a>
<ul class="sub-menu">
<li class="menu-item"> <a href="<?php echo bp_loggedin_user_domain() ?>groups/">My Groups</a></li>
</ul>
</li>
<!--end menu--->
<!-- new menu here edit the links-->
<li class="menu-item"id="four"> <a href="http://my_site.com/events/">All Events</a>
<ul class="sub-menu">
<li class="menu-item"> <a href="http://my_site.com/events-calander/">Calendar View</a></li>
<li class="menu-item"id="four"> <a href="<?php echo bp_loggedin_user_domain() ?>events/my-events/">My Events</a></li>
<li class="menu-item"id="four"> <a href="<?php echo bp_loggedin_user_domain() ?>events/my-events/">Create an Event</a></li>
</ul>
</li>
<!--end menu--->
<?php
}
}
add_action("bp_nav_items","add_profile_link_to_nav");