0

Hi I have a navigation bar that contain two types of news TOP and Upcoming with subcategories and I have following code that adds class='current' when subcategory for example "economic" from upcoming is selected but when I press on the same category but from TOP news it anyway activates Upcoming .

<?PHP
    $category = $_REQUEST[category];

    echo "<ul id='frumos'>";
        echo "<li ";
        if($category == 'economic'){
            echo " class='current'";
        }
        echo "><a href='/upcoming.php?category=economic'>Economic</a></li> ";
        echo "<li";
        if($category == 'other'){
            echo " class='current'";
        }
        echo "><a href='/upcoming.php?category=other'>Freestyle</a></li>";
        echo "<li";
        if($category == 'social'){
            echo " class='current'";
        }
        echo "><a href='/upcoming.php?category=social'>Social</a></li>";
    echo "</ul>";
    ?>

I am new in PHP and I tried this code but it doesn't work (original menu here )

  <?PHP
        $category = $_REQUEST[category];
   if ($pagename eq 'upcoming')
        echo "<ul id='frumos'>";
            echo "<li ";
            if($category == 'economic'){
                echo " class='current'";
            }
            echo "><a href='/upcoming.php?category=economic'>Economic</a></li> ";
    else
         echo "<ul id='frumos'>";
            echo "<li ";
            if($category == 'economic'){
                echo " class='current'";
            }
            echo "><a href='/?category=economic'>Economic</a></li> ";
            echo "<li";
            if($category == 'other'){
                echo " class='current'";
            }
            echo "><a href='/upcoming.php?category=other'>Freestyle</a></li>";
            echo "<li";
            if($category == 'social'){
                echo " class='current'";
            }
            echo "><a href='/upcoming.php?category=social'>Social</a></li>";
        echo "</ul>";
        ?>
Andrew Ceban
  • 118
  • 15

1 Answers1

0

You have missed some braces. I am not sure if this is what you intended but it is the place to start.

<?PHP
    $category = $_REQUEST[category];
if ($pagename eq 'upcoming') {
    echo "<ul id='frumos'>";
        echo "<li ";
        if($category == 'economic'){
            echo " class='current'";
        }
        echo "><a href='/upcoming.php?category=economic'>Economic</a></li> ";
} else {
     echo "<ul id='frumos'>";
        echo "<li ";
        if($category == 'economic'){
            echo " class='current'";
        }
        echo "><a href='/?category=economic'>Economic</a></li> ";
        echo "<li";
        if($category == 'other'){
            echo " class='current'";
        }
        echo "><a href='/upcoming.php?category=other'>Freestyle</a></li>";
        echo "<li";
        if($category == 'social'){
            echo " class='current'";
        }
        echo "><a href='/upcoming.php?category=social'>Social</a></li>";
}
echo "</ul>";
?>
karmafunk
  • 1,453
  • 12
  • 20