Jump to content

Recommended Posts

Function:

	<?php function menu($name, $class='') {
	$uri = $_SERVER['REQUEST_URI'];
	switch($name){
		case 'menu-main':
			$r = mysql_query("SELECT page_name, page_url FROM " . CONTENT . " WHERE menu_id = 'main' AND page_active = '1'");
			while($row = mysql_fetch_array($r, MYSQL_ASSOC)){
				echo "<li";
				if ($row['page_url'] == $uri)
					$class .= ' current_page_item';

				echo " class=\"" . $class . "\"";
				echo "><a href=\"" . $this->base() . $row['page_url'] . "\">" . ucfirst($row['page_name']) . "</a></li>\n";
			}
		break;
	}
}?>

 

Page:

	<?php $cms->menu('menu-main', 'page_item'); ?>

 

Table:

TABLE `content` (
  `menu_id` varchar(20) NOT NULL default '',
  `page_name` varchar(255) NOT NULL default '',
  `page_url` varchar(255) default NULL,
)

 

The site location: http://cms.iarp.ca/

 

While on the home page, the menu links all contain current_page_item, when you view Haiz, home doesn't but the rest do... and so on as you click each page. I've spent abit trying to figure out what i'm doing wrong and i'm stuck. Help please.

 

The Problem: Only the current page your viewing, should have the current_page_item class.

Link to comment
https://forums.phpfreaks.com/topic/138582-solved-trying-to-select-an-exact-row/
Share on other sites

Change

echo "<li";
               if ($row['page_url'] == $uri)
                  $class .= ' current_page_item';
               
               echo " class=\"" . $class . "\"";

 

To

               echo '<li class="' . $class . (($row['page_url'] == $uri) ? ' current_page_item' : null) . '"';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.