Jump to content

[SOLVED] how to make variable links.


fallingintoZero

Recommended Posts

i've been scowering the internet, and serching this forum, and can't seem to find any tutorials on how to create variable links. maybe i am not searching the right words or phrases, but i'm at a loss.

 

i am trying to make different links based off an index.php page. all the pages are generally the same, but display different content.

 

the body of the index.php page is pretty simple and ran off includes:

<body>
<div id="page">
<?php include ('header.php') ?>
<div id="wrapper" class="clearfix">
<div id="content" class="widecolumn">
<h2 class="title">Home (n.)</h2>
<?php include ('index_content.php') ?>
</div>
<?php include ('sidebar.php') ?>
</div>
<?php include ('footer.php') ?>
</div>
</body>

 

each other page is pretty much the same, for example, contact.php is:

 

<body>
<div id="page">
<?php include ('header.php') ?>
<div id="wrapper" class="clearfix">
<div id="content" class="widecolumn">
<h2 class="title">Contact (n.)</h2>
<?php include ('contact_content.php') ?>
</div>
<?php include ('sidebar.php') ?>
</div>
<?php include ('footer.php') ?>
</div>

 

each page has the same includes, one of which is sidebar.php, which is the navigation menu.

 

	<div id="sidebar">
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<style type="text/css">
<!--
.style3 {color: #d8d7d3}
-->
        </style>


					<h3>Main Menu</h3>			
					<ul class="style3">

			<li><a href="index.php">home.</a></li>
            <li><a href="about.php">about.</a></li>
	<li><a href="external.php">external.</a></li>
		<li><a href="contact.php">contact.</a></li>
		</ul>
</body>
</html>

</div>

 

 

as you see, each link is it's own file. about.php, external.php, contact.php, etc. i'd like to make the links variable links so the addresses would be something like index.php?page=about, index.php?page=external, so forth so forth... and the content would display in the div tags, rather then seperate pages, with seperate includes to where the content is.

 

also, i'm trying to set a flash intro to also be index.php, so i'd be setting the current index.php to index.php?page=home.

 

can anyone give some advice or direction as to how i would go about doing this?

Link to comment
Share on other sites

you can try this...

<?php
if(isset($_GET['page'])){
switch($_GET['page']){
	case'home':
		include'home.php';
		break;
	case'external':
		include'external.php'
		break;
	case'ect........':
	     //stuff here
		 break;
	default:
		include'home.php';
}
}
or this 

if(isset($_GET['page'])){
switch($_GET['page']){
	case'home':
		//stuff here 
	case'external':
		//stuff here 
	case'ect........':
	     //stuff here
		 break;
	default:
		include'home.php';
}
}
?>

 

hope that helps

Link to comment
Share on other sites

sorry im lost ...

 

if you are going to use the first sample you have to create a separate pages for home.php external.php and include them like i did..

 

if you are going to use sample number to create a page where it has all the data to be loaded and divide them according to each cases

 

eg.. case home put the date for home on that case

 

case 'home':

    your code here that will out output the data's from home

Link to comment
Share on other sites

maybe you missed  the terminator ;  include'external.php' ;

 

my bad sorry about that ..

 

i should have noticed that myself lol. okay, everything pretty much works perfectly. the only problem is the default content isn't loading. the default and home content is the same, and are both linked the same. but if i just go to index2.php, nothing shows up. it's all blank. but if i click home, the content shows up.

 

<div id="wrapper" class="clearfix">
<div id="content" class="widecolumn">
<?php
if(isset($_GET['page'])){
switch($_GET['page']){
	case'home':
		include'index_content.php';
		break;
	case'external':
		include'external_content.php';
		break;
	case'about':
		include'about_content.php';
		break;
	default:
		include'index_content.php';
}
}
?>
</div>

 

 

Link to comment
Share on other sites

hmm. well i just switched everything over to be index.php, and same thing. it seems like it's not recognizing anything to be the default content. any idea if there's any work around?

 

edit: should the default be set as a require rather then an include?

edit2: ignore that. it didn't work either.

Link to comment
Share on other sites

try to look at your query string ....

see the url and paste here

 

i'm not sure what you mean. sorry, i feel kinda stupid right about now lol

 

i also just realized that i didn't really explain things right. i didn't mean to say nothing shows up. i meant to say the content of index_content.php doesn't show up. http://www.redeemedplaces.com/test is where i'm running the test index.php, if you wanted to see what i mean. content doesn't show up by default. i have to click home for it to display

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.