在这个网站上: http://jumpthru.net/newsite/vision/
我使用 CSS sprites 进行导航,使用 PHP else 语句显示当前页面的事件状态。除了包含循环/博客帖子的页面 (http://jumpthru.net/newsite/commentary/)
我需要为这个页面调用不同的 php 吗?
PHP:
<?php
if ( is_page('vision') ) { $current1 = 'visionside a'; }
elseif ( is_page('team') ) { $current2 = 'teamside a'; }
elseif ( is_page('commentary') ) { $current3 = 'blogside a'; }
elseif ( is_page('organizations') ) { $current4 = 'orgside a'; }
?>
CSS:
#sidebarnav ul#sidenav li.<?php echo $current1; ?> {
background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/vision2.png) 0px -106px !important;
#sidebarnav ul#sidenav li.<?php echo $current2; ?> {
background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/team2.png) 0px -106px !important;
#sidebarnav ul#sidenav li.<?php echo $current3; ?> {
background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/content2.png) 0px -106px !important;
#sidebarnav ul#sidenav li.<?php echo $current4; ?> {
background:url(http://jumpthru.net/newsite/wp-content/themes/twentyten/images/side/org2.png) 0px -106px !important;
如有任何帮助,我们将不胜感激!
最佳答案
我的解决方案与您正在寻找的略有不同,但比您正在做的要好得多。
PHP:
<?php
if ( is_page('vision') )
$page = 'vision';
elseif ( is_page('team') )
$page = 'team';
elseif ( is_page('commentary') )
$page = 'blog';
elseif ( is_page('organizations') )
$page = 'org';
?>
<body id="page-<?php echo $page; ?>">
...
注意上面的 PHP:如果你有一个 get_page_id()
功能,你可以进一步简化这个。通过简单地拥有 <body id="page-<?php get_page_id(); ?>">
HTML:
<ul id="sidenav">
<li class="visionside"><a href="#">...</a></li>
<li class="teamside"><a href="#">...</a></li>
<li class="blogside"><a href="#">...</a></li>
<li class="orgside"><a href="#">...</a></li>
</ul>
CSS:
body#page-vision #sidenav li.visionside a,
#sidenav li.visionside a:hover {
...
}
注意上面的 CSS:上面列出的两行可以一起设置样式 - 当前状态和悬停状态。这将使您将鼠标悬停在导航上时显示当前状态,而不管哪个导航是“当前”导航。
看到您对使用 CSS Sprites 感兴趣,我绝对建议您继续阅读 this article .
关于php - CSS Sprites 和 PHP 使用动态菜单突出显示不使用循环功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6318699/