English 中文(简体)
• 如何利用电 to进行目前的页面选择
原标题:How to have current page selection using inludes navigation

我正在使用Sphp,包括在我的网页上限制 red余,在我航行时,我怎么能选择我航行的当前网页,但以某种颜色为座标。 php档案。

如果说在家里添加“活性”类。 php项目和增加一种风格,这样看不出不同之处,我的所有页页上都会发生这种情况,因此,我首先要包括我如何有一位负责人。 该网站载有我的导航,这还使每一页能够显示你在导航中反映的当前页面?

这是头盔的零。 网址

  <ul>
 <li><a href="index.php">About Us</a></li>
 <li><a href="portfolio.php">Portfolio</a></li>
 <li><a href="news.php">News</a></li>
 <li><a href="contact.php">Contact</a></li>
    </ul>

这是指数。 php称头盔。 网址上包括:

  <?php
   include("includes/header.php");
  ?>

 <div class="span-8" id="welcome">
  <p>Lorem ipsum</p>
 </div>

 <div class="span-16 last" id="slideshow">
  <img src="images/introImage1.png" alt="fountain">
  <img src="images/introImage2.png" alt="bench">
  <img src="images/introImage3.png" alt="bridge">
 </div>

 <?php
  include("includes/footer.php");
  ?>
最佳回答

为此:

<ul>
<?php 
$pages = array( index.php  =>  About Us ,  portfolio.php  =>  Portfolio ,  news.php  =>  News ,  contact.php  =>  Contact );

foreach($pages as $url => $title) {
   $li =  <li  ;
   if($_SERVER[  PHP_SELF  ] == $url) {
       $li .=  class="active" ;
   }
   $li .=  ><a href="  . $url .  ">  . $title .  </a></li> ;
   echo $li;
}

?>
</ul>
问题回答

另一种选择是,根据<代码> <> >s tag设定一个属性,然后使用相应的配对机来改变任何部分的搭配。

因此,在你的主要网页(home)上,你可以:

<body id="home">
<a href="/" class="home">Home</a>
<a href="/about.htm" class="about">About Us</a>

其后,在贵安会内:

body#home a.home , body#about a.about {
  color:#999;background-color:#000; }

另一种选择是,在实际页内列入一个特别安全声明。

<style type="text/css">
  a[href="<?php echo basename( $_SERVER[ PHP_SELF ] ); ?>"] ,
  a[href="<?php echo $_SERVER[ PHP_SELF ]; ?>"] {
  /* Styles for Current Page Links */ }
</style>

当然,这取决于浏览器能够使用CSS选择器。

而且,如果你想完全确定与档案的所有联系(包括完整的国际独立人士协会),那么,还包括以下选择:

a[href="http<?php
  echo ( $_SERVER[ HTTPS ] ?  s  :    ). :// .
    $_SERVER[ HTTP_HOST ].(
      ( $_SERVER[ HTTPS ] && $_SERVER[ SERVER_PORT ]!=443 )
      || ( !$_SERVER[ HTTPS ] && $_SERVER[ SERVER_PORT ]!=80 ) ?
       : .$_SERVER[ SERVER_PORT ] :    ).
    $_SERVER[ PHP_SELF ]; ?>"]

<>执行>: 更正 PHP 可以使用。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签