Tizag Webmaster Forums  

Go Back   Tizag Webmaster Forums > User Submissions > Tutorial Forum

Reply
 
Thread Tools Display Modes
  #11  
Old 08-23-2009, 02:43 PM
richei richei is offline
Professor
 
Join Date: Apr 2007
Location: Smithfield, VA
Posts: 3,175
richei is a jewel in the roughrichei is a jewel in the rough
Send a message via MSN to richei
yea even from a design point of view its pointless, because it doesn't matter. it already knows which link is active by default, hence a:active. all you have to do is slap that in your css and you're golden.
__________________
Unlimited Web Hosting
If i actually managed to help you in any way, please +rep me!
Reply With Quote
  #12  
Old 08-23-2009, 04:47 PM
websprite websprite is offline
Newbie
 
Join Date: Aug 2009
Posts: 16
websprite will become famous soon enough
Explain yourself

why from a design point of view is it worthless. how will it know by default which link is active by default?
you are talking about something totally different, you are talking about pseudo-class not a class or id, which can't do which I posted, which changes the style of the link, which a:active will not do

You keep posting but don't offer better alternatives, if you have better, then post it. I read a post by yourself, where you told someone to take php from there sig, if being superior helps you feel big, fine, but without explaining yourself you're here and what you said to that person I feel you coming across to me personally not very good.

If you care to show me you better way, then please go aheard, you are more then welcome

Last edited by websprite; 08-23-2009 at 05:16 PM.
Reply With Quote
  #13  
Old 08-23-2009, 05:27 PM
Steven's Avatar
Steven Steven is offline
Graduate Student
 
Join Date: Oct 2007
Location: Colorado, USA
Posts: 987
Steven has a spectacular aura aboutSteven has a spectacular aura about
Send a message via AIM to Steven Send a message via MSN to Steven
PHP Code:
foreach( $pages as $page => $link )
{
     
$class = ( $page === $id ) ? ' class="active"' null;
     echo 
'<li',$class,'><a href="',$link,'">',$page,'</a></li>';

Three lines.
__________________
.
Did I help you in any way? Please return the favor.

Please remember to use [php] [html] or [code] tags when appropriate.
Reply With Quote
  #14  
Old 08-23-2009, 05:43 PM
websprite websprite is offline
Newbie
 
Join Date: Aug 2009
Posts: 16
websprite will become famous soon enough
Quote:
Originally Posted by Steven View Post
PHP Code:
foreach( $pages as $page => $link )
{
     
$class = ( $page === $id ) ? ' class="active"' null;
     echo 
'<li',$class,'><a href="',$link,'">',$page,'</a></li>';

Three lines.
3 lines, yes there, but you also have to add other code to make it work, it won't work by itself,

I will request this thread to be deleted to make you all happy.
Reply With Quote
  #15  
Old 08-23-2009, 05:53 PM
Steven's Avatar
Steven Steven is offline
Graduate Student
 
Join Date: Oct 2007
Location: Colorado, USA
Posts: 987
Steven has a spectacular aura aboutSteven has a spectacular aura about
Send a message via AIM to Steven Send a message via MSN to Steven
PHP Code:
function display_menu($id)
{
    
$pages = array(
        
'home' => 'home.php',
        
'about' => 'about.php',
        
'contact' => 'contact.php'
    
);
    
    if( !
array_key_exists($id,$pages) ) { return false; }
    
    echo 
'<ul>';
    foreach( 
$pages as $page => $link )
    {
        
$class = ( $page === $id ) ? 'class="active" ' null;
        echo 
'<li',$class,'><a href="',$link,'">',$page,'</a></li>';
    }
    echo 
'</ul>';

Why request the thread be deleted? This is a discussion forum, a place to learn. Don't get ticked simply because more experienced programmers have better ways to do something.
__________________
.
Did I help you in any way? Please return the favor.

Please remember to use [php] [html] or [code] tags when appropriate.
Reply With Quote
  #16  
Old 08-23-2009, 05:56 PM
DragoNero's Avatar
DragoNero DragoNero is offline
Professor
 
Join Date: Oct 2006
Location: My House - UK
Posts: 2,822
DragoNero is just really niceDragoNero is just really niceDragoNero is just really nice
Send a message via MSN to DragoNero
All you need is an array containing the page names.

eg:
PHP Code:
$pages = array('index' => 'index.php''My Page 1' => 'page1.php''Page # 2' => 'page2.php''My Page 3' => 'page3.php''Page # 4' => 'page4.php''My Page 5' => 'page5.php'); 


I'm sorry that this thread has turned into a flame thread but the following has to be said:

There is no point in getting upset/angry at people for criticising your post. Maybe someone will find it useful, maybe not. Maybe someone can tell you how to make it better or maybe someone will tell you that your doing it wrong. Either way this is a public forum and that being so anything posted here is open to criticism.
__________________
Ben/19/PHP, MySQL, HTML, CSS, Javascript (+ Ajax), c, C#, c++, Dot,
`~_~` Don't forget to ++rep (Thanks!)
If you wish to have a rapid reply email me by clicking my name and selecting "Send email to..." or by downloading the vCard on my profile under "Contact Info"
Reply With Quote
  #17  
Old 08-24-2009, 11:58 AM
mabersoft's Avatar
mabersoft mabersoft is offline
Newbie
 
Join Date: Aug 2009
Posts: 13
mabersoft will become famous soon enough
Great Tutorial.

I will be using this on my new website.
Reply With Quote
  #18  
Old 10-26-2009, 09:02 PM
geomcd geomcd is offline
Curious Visitor
 
Join Date: Oct 2009
Posts: 1
geomcd will become famous soon enough
Menu Current Pages

Am wondering what the shorter way to indicate the current page is, as hinted at by richei:

"So basically, you have a whole lot of code that really does nothing other than take up space. all that code can be taken down to 1 link

<a href="index.php?page=page1&id=active">Page one</a></li>

no php needed in the link, no complicated functions to troubleshoot. put some if statements or a switch on the index page to tell what to include and you have yourself a php menu."

Can you give a fuller example, keeping in mind the lesser abilities and knowledge of others?

Thanks.

George
Reply With Quote
  #19  
Old 11-03-2009, 11:48 AM
richei richei is offline
Professor
 
Join Date: Apr 2007
Location: Smithfield, VA
Posts: 3,175
richei is a jewel in the roughrichei is a jewel in the rough
Send a message via MSN to richei
you'll still need the php on the other pages to tell it what to do with id=active, otherwise its really of no use, and it doesn't really help, since you don't have a way of telling that the other pages aren't active.

but still, you don't need php to tell it which links are active or not, css already does it for you with a:active.

#menu a:active {
text-dectoration: none;
color: red;
}

changes any active link in the menu to red. very easy to use, no php is needed.
__________________
Unlimited Web Hosting
If i actually managed to help you in any way, please +rep me!
Reply With Quote
Reply

Thread Tools
Display Modes

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

Forum Jump


All times are GMT -6. The time now is 04:19 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2008, Tizag