Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using the following to get the active page url:

<?php
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;
}
?>

echoing the above gives me my URL as follows:

http://www.domain-nane.com/index.php?option=com_content&view=article&id=6&Itemid=109

I want to add a class of 'current' to my 'li' if the active page is present - dependant on the 'Itemid' contained in the url - i.e.

<li class="current">
   <a href="index.php?option=com_content&amp;view=article&amp;id=6&amp;Itemid=109">Link 1</a>
<li>
   <a href="index.php?option=com_content&amp;view=article&amp;id=6&amp;Itemid=110">Link 2</a>
</li>
<li>
   <a href="index.php?option=com_content&amp;view=article&amp;id=6&amp;Itemid=111">Link 3</a>
</li>

Any hints/ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
484 views
Welcome To Ask or Share your Answers For Others

1 Answer

you are doing wrong thing

simple way is below..

In your URL Itemid is unique, so its better to do this in following way

<li <?php if($Itemid == $_REQUEST['Itemid']) { echo class='current'; } ?> >
   <a href="index.php?option=com_content&amp;view=article&amp;id=6&amp;Itemid=109">Link 1</a>
</li>

<li <?php if($Itemid == $_REQUEST['Itemid']) { echo class='current'; } ?> >
   <a href="index.php?option=com_content&amp;view=article&amp;id=6&amp;Itemid=110">Link 2</a>
</li>

<li <?php if($Itemid == $_REQUEST['Itemid']) { echo class='current'; } ?> >
   <a href="index.php?option=com_content&amp;view=article&amp;id=6&amp;Itemid=111">Link 3</a>
</li>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...