Jump to content

[SOLVED] Handling nav with switch problem


bob_arctor

Recommended Posts

Hello all,

Pretty new to this - Here's my problem.

Currently using a php include(),works fine, to handle navigation -

 

<div id="nav">
<ul>
  <li><a <?php if ($this_page=="Home") echo "id=\"currentpage\""; ?> href="index">Home</a></li>
  <li><a <?php if ($this_page=="About") echo "id=\"currentpage\""; ?> href="about">About</a></li>
  etc.
</ul>
</div>

 

Several pages (error 404, privacy etc.) require that only some nav options are available.

I do not want to code an include for each page - kind of defeats the point.

Tried this -

 

<?php
$page = $this_page; 

switch($page){
    case "Home":
    /*some code here*/
    break;
    etc.
    etc.
    case "404":
    echo  ' <div id="nav">
  	     <ul>
  	       <li><a <?php if ($this_page=="Home") echo "id=\"currentpage\""; ?> href="index">Home</a></li>
  	       <li><a <?php if ($this_page=="Contact") echo "id=\"currentpage\"";?> href="http="contact">Contact</a></li>
     </ul>
           </div> ';
    break;
    default:
    break; } ?>

 

This gives me the nav bars which literally display "href ="index">Home" "href ="contact">Contact" contained inside.

Where am I going wrong ?

I'm pretty sure I should be revisiting php 101.

I just cannot see it.

Is there a more eloquent way to go about this ?

Regards.

 

Link to comment
https://forums.phpfreaks.com/topic/111334-solved-handling-nav-with-switch-problem/
Share on other sites

case "404":

echo   "<div id='nav'>
              <ul>
                 <li><a id = 'currentpage' href='$this_page'>$this_page</a></li>
  	         <li><a id = 'currentpage' href='$this_page'>$this_page</a></li>
              </ul>
           </div> ";

break;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.