Вопрос по php – Применить определенный класс / идентификатор к текущей странице в меню (PHP)

2

Error: User Rate Limit Exceeded

<div id="blahblah" style="blahblah">
<a href="http://domain.com/folder/biography"><img style="blahblah" src="blahblahblahblah"></a>
<a href="http://domain.com/folder/contacts"><img style="blahblah" src="blahblahblahblah"></a>
<a href="http://domain.com/folder/gallery"><img style="blahblah" src="blahblahblahblah"></a>
<a href="http://domain.com/folder/dontknow"><img style="blahblah" src="blahblahblahblah"></a>
</div>

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

<div id="blahblah" style="blahblah">
<a <?php if (strpos($_SERVER['PHP_SELF'], 'biography')) echo 'class="current"';?> href="http://domain.com/folder/biography"><img style="blahblah" src="blahblahblahblah"></a>
<a <?php if (strpos($_SERVER['PHP_SELF'], 'contacts')) echo 'class="current"';?> href="http://domain.com/folder/contacts"><img style="blahblah" src="blahblahblahblah"></a>
...
...
</div>

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded!== falseError: User Rate Limit Exceeded keithhatfield

Ваш Ответ

3   ответа
1

Error: User Rate Limit Exceeded

1

Error: User Rate Limit Exceededstrpos()Error: User Rate Limit Exceeded

<?php $current = basename($path, ".php"); ?>

<a href="blahblah"<?php if ($current == 'biographies') echo ' class="current"'; ?> />

$currentError: User Rate Limit Exceeded.phpError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded MultiformeIngegno
Error: User Rate Limit Exceeded
3

Error: User Rate Limit Exceeded

  1. check the result of strpos() with !== false.
  2. Use $_SERVER['REQUEST_URI'] rather than $_SERVER['PHP_SELF'].
  3. Wrap the code inside a function.

Error: User Rate Limit Exceeded

<?php
function get_current($name) {
  if (strpos($_SERVER['REQUEST_URI'], $name) !== false)
    echo 'class="current"';
}
?>

<div id="blahblah" style="blahblah">
  <a <?php get_current('biography') ?> href="http://domain.com/folder/biography"><img style="blahblah" src="blahblahblahblah"></a>
  <a <?php get_current('contacts') ?> href="http://domain.com/folder/contacts"><img style="blahblah" src="blahblahblahblah"></a>
  ...
  ...
</div>
Error: User Rate Limit Exceededstackoverflow.com/questions/10886203/… MultiformeIngegno
Error: User Rate Limit Exceeded MultiformeIngegno
Error: User Rate Limit Exceededdomain.com/folder/biography"><imgError: User Rate Limit Exceeded MultiformeIngegno
Error: User Rate Limit Exceededget_current('page1', 'page2', 'page3')Error: User Rate Limit Exceededfunc_get_args()Error: User Rate Limit Exceeded

Похожие вопросы