CSS Sprites和PHP使用动态菜单突出显示不能使用循环功能 [英] CSS Sprites and PHP using dynamic menu highlighting not working with loop function

查看:195
本文介绍了CSS Sprites和PHP使用动态菜单突出显示不能使用循环功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此网站上:
http://jumpthru.net/newsite/vision/

我使用CSS sprites作为导航,使用PHP else语句显示当前页面的活动状态。除了包含循环/博客帖子的网页( http://jumpthru.net),所有网页都能正常工作/ newsite / commentary /

I am using CSS sprites for my navigation with PHP else statements to show the active state for the current page. All of the pages are working properly except for the page that contains the loop / blog postings ( http://jumpthru.net/newsite/commentary/)

我需要以不同的方式呼叫此网页吗?

Do I need to call the php differently for this page?

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;

}

任何帮助赞赏!

推荐答案

我有一个解决方案,有点不同于你正在寻找,但是一个更好的解决方案您正在做什么。

I have a solution that is a bit different than what you are looking for, but is a much better solution to what you are doing.

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; ?>">
...

:如果你有一个 get_page_id()函数,你可以简化这一点更多。只需拥有< body id =page-<?php get_page_id();?">

Note about above PHP: If you had a get_page_id() function, you could simplify this a lot more. by simply having <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 :上面列出了两行,状态和悬停状态。

Note about above CSS: There are two lines listed above that you can style together - the current state, and the hover state. This will make the current state display when you hover over the nav, regardless of which nav is the "current" nav.

查看您感兴趣的内容时,将鼠标悬停在导航栏上时,在使用CSS Sprites时,我一定会建议您阅读这篇文章

Seeing that you're interested in using CSS Sprites, I would definitely recommend that you read up on this article.

这篇关于CSS Sprites和PHP使用动态菜单突出显示不能使用循环功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆