Jump to content

Recommended Posts

Hi there,

 

A few years ago I had this great php script that would make 'active' menulinks when you were on the designated page.

section=news, menulink news would become active (bold and different colour).

 

Recently I have started working on it again but I found out it doesn't work anymore the way it should.

Only the home page is displayed, even though you click on news, contact or any other page.

 

I use a different directory for every section, so index.php?section=news&page=main to link.

 

Here's the code if the index page :

 

<HTML>
<?php

if (!isset($section))
{
	$section='home';
}

if (!isset($sub))
{
	$sub='';
}
else
{
	$sub .= '/';
}

if (!isset($menu))
{
	$menu='menu';
}

if (!isset($page))
{
	$page='main';
}


// include header
print("<head>");

include("home/header.php");



print("</head>");

// body
print("<BODY MARGINWIDTH=\"0\" MARGINHEIGHT=\"0\" LEFTMARGIN=\"0\" TOPMARGIN=\"0\" bgcolor=#CCCCFF>");

// include top (logo & menu)
include("home/top.php");

// include menu for $section and $sub
if (file_exists("$section/$sub$menu.php"))
{
	include("$section/$sub$menu.php");
}
elseif (file_exists("$section/$menu.php"))
{
	include("$section/menu.php");
}
else
{
	include("home/menu.php");
}


// include page in sub in section
if (file_exists("$section/$sub$page.php"))
{
	include("$section/$sub$page.php");
}
else
{
	include("home/error404.php");
}

// include bottom
include("home/bottom.php");

?>
</HTML>

 

In my top.php the menulinks are coded like this

<a class="menu<?php if($section == 'home') print("over"); ?>" href="index.php?section=home" title="Klik op Visie als u onze visie wilt weten over webdesign"><b>home</b></a>

 

Can anyone help, I'm totally stuck and I can't remember how I solved this before.

 

Thanks in advance,

Link to comment
https://forums.phpfreaks.com/topic/125062-solved-creating-a-menu-with-sections/
Share on other sites

Not solved, just ran into a problem with the sub section.

 

For example:

 

index.php?section=news&page=archive

 

That page won't be displayed and I'm stuck on the main page of that section.

 

Tried to ajust to code as I did with section bit but keep getting an error.

 

Here's what I changed it to

 

<HTML>
<?php
$section = $_GET['section'];
if (!isset($section))
{
	$section='home';
}
	if (!isset($sub))
{
	$sub='';
}
else
{
	$sub .= '/';
}

if (!isset($menu))
{
	$menu='menu';
}

if (!isset($page))
{
	$page='main';
}

 

Any suggestion?

This got my a bit further but still no subpages displayed

 

$section = $_GET['section'];
if (!isset($section))
{
	$section='home';
}
$sub = $_GET['sub'];
	if (!isset($sub))
{
	$sub='';
}
else
{
	$sub .= '/';
}

if (!isset($menu))
{
	$menu='menu';
}

if (!isset($page))
{
	$page='main';
}

And solved by ajusting both $sub, $menu & $page.

 

Working code

<?php
$section = $_GET['section'];
if (!isset($section))
{
	$section='home';
}
$sub = $_GET['sub'];
	if (!isset($sub))
{
	$sub='';
}
else
{
	$sub .= '/';
}
$menu = $_GET['menu'];
if (!isset($menu))
{
	$menu='menu';
}
$page = $_GET['page'];
if (!isset($page))
{
	$page='main';
}

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.