Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Updating link in nav if on that page
Old 07-22-2010, 02:02 AM [SOLVED]Updating link in nav if on that page
Novice Talker

Posts: 7
Trades: 0
Solved: I added the trim function around the str_replace function found in the functions.php file. Just turned to be a space problem


ey everyone, I have an array of links that I'm echoing out into an unordered list that I am using for a sites navigation.

I would like to change the color of a link to show that the user is currently on that page.

Here's the code I have so far:

functions.php
PHP Code:
function getScriptName() {

return 
str_replace('/'' ',$_SERVER['SCRIPT_NAME']);

page.php
PHP Code:
$scriptname getScriptName();

            
                
$links = array('index.php' => 'Home''portfolio.php' => 'Portfolio''page.php' => 'Blog''about.php' => 'About');
                
                foreach (
$links as $url => $description) {
                    if (
strcmp($scriptname$url) == 0) {
                        echo 
'<li><a href="' $url '" title=""><span style="background: #63AFD0;" >' .$description'</span></a></li>';
                    }
                    else {
                        echo 
"<li><a href=\"$url\" title=\"\">$description</a></li>";
                    }
                } 
I tried echoing out the result of the string comparison, but it gave a -1 each time. Any ideas?

P.S. I have included the functions file in the page.php file.

Last edited by cchase88; 07-22-2010 at 02:32 AM..
cchase88 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-22-2010, 07:56 AM Re: Updating link in nav if on that page
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
Try this.
PHP Code:
<?php
$self 
$_SERVER['SCRIPT_NAME'];

$links = array('index.php' => 'Home''portfolio.php' => 'Portfolio''page.php' => 'Blog''about.php' => 'About'); 
                 
                foreach (
$links as $url => $description) { 
                    if(
strpos($self$url) !== FALSE) {
                        echo 
'<li><a href="' $url '" title=""><span style="background: #63AFD0;" >' .$description'</span></a></li>'
                    } 
                    else { 
                        echo 
"<li><a href=\"$url\" title=\"\">$description</a></li>"
                    } 
                }  
?>
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels

Last edited by shivaji; 07-22-2010 at 07:58 AM.. Reason: UUPSSSS! I didn't see you are solved. :(
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Reply     « Reply to Updating link in nav if on that page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23011 seconds with 12 queries