Jump to content

PHP include .html pages and marked menus help


Lovac

Recommended Posts

Hello to the community, i need help with some things.

 

im using this code to change the pages with links in menu:

 

<?php 												
$str = $_GET['str'];
if(strlen($str) && preg_match('/^[\-_a-z0-9]*$/i', $str))
{
if(!include $str . ".html")
{
include "index.html";
}
}
else
{
include "index.html";
}
?>

 

then in menus this:

<a href="index.php?str=page_2">Page2</a>

 

Now what code i need to add or change to get things on menus marked on which page are you atm?

Page1 Page2 Page3

Page1 Page2 Page3 (when you are on page3)

Link to comment
Share on other sites

I guess you could do something like this

 

 

<?php
//Full page list
$pages = array(
"page_1"=>"Main Page",
"page_2"=>"Page2",
"page_3"=>"Page3",
"page_4"=>"Page4",
);

//Get Page selected
$page = (empty($_GET['str']))?0:$_GET['str'];

//Display links
echo PageLinks($page,$pages);

//check selected page is correct name format
if(preg_match('/^[\-_a-z0-9]+$/i', $page)){
$file = "$page.html";
//check page exists
if(file_exists($file)){
	include($file);
	exit;
}
}
//any faults display home page
include "index.html";

function PageLinks($page, $pages){
$str = "";
foreach($pages as $k => $v){
	if($page == $k){
		$str .="<p><strong><a href=\"index.php?str=$k\">$v</a></strong></p>\n";
	}else{
		$str .="<p><a href=\"index.php?str=$k\">$v</a></p>\n";
	}
}
return $str;
}
?>

Link to comment
Share on other sites

If you can post a HTML example of the selected page and unselected pages i could update it for you.

basically your need to change

if($page == $k){
         $str .="<p><strong><a href=\"index.php?str=$k\">$v</a></strong></p>\n";
      }else{
         $str .="<p><a href=\"index.php?str=$k\">$v</a></p>\n";
      }

to something like this

if($page == $k){
         $str .="<p class=\"selected\"><strong><a href=\"index.php?str=$k\">$v</a></strong></p>\n";
      }else{
         $str .="<p class=\"unselected\"><a href=\"index.php?str=$k\">$v</a></p>\n";
      }

Link to comment
Share on other sites

tried but look what happens:

 

this is default menu:

page1 page2 page3 page4

 

when you click on page2 for example it turns like this:

page1 page2 page3 page3

 

but my problem is that until you click something on menu its like this, when you enter site its behaves like its allways on selected:

page1 page2 page3 page4

 

 

Link to comment
Share on other sites

for a default page you can update the code

//Get Page selected
$page = (empty($_GET['str']))?0:$_GET['str'];

to

//Get Page selected
$page = (empty($_GET['str']))?"page_1":$_GET['str'];

that will make page_1 the default page.

 

can you post the PageLinks function and I'll take a look

Link to comment
Share on other sites

hello, need more help please.

not sure if you got my msg, but this is the problem now which i didnt noticed before:

 

this is bottom of page which uses this php, its ok, you can scroll to the end of page where is copyright (i cuted it out on this pic)

http://www.imagesforme.com/show.php/919785_botom1.jpg

 

when using menu bottom of page is cutted of, finishing edged, copyright part and grey background, all are missing and cant scroll further then contents ends:

http://www.imagesforme.com/show.php/919786_botom2.jpg

Link to comment
Share on other sites

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.