Reputation: 262
Forgive me as I am still kinda new at web development. :)
Normally when I create my websites I create a file called header.html and footer.html and just include this files into my webpages to be consistent also so that I only change data once then add whatever code is necessary. (Eg: index.php)
<?php
include ('includes/header.html');
include ('html/index.html');
include ('includes/footer.html');
//other php codes
?>
Now my problem is that on one of my pages (food-menu.php), I have a sidebar that has got links that I have setup to retrieve the pages according to the links that are clicked - and the code that I am currently works in terms of retrieving dynamic content. My only problem is how can i setup a default content include on that page before it goes dynamic?
The sidebar goes like this:
//Sidebar
<section class="widget">
<h3 class="title">Main Menu</h3>
<ul>
<li><a href="?link=1" name="link1" title="View all Cold Starters">Cold Starters</a></li>
<li><a href="?link=2" name="link2" title="View all Hot Starters">Hot Starters</a></li>
<li><a href="?link=3" name="link3" title="View all Charcoal Grilled">Charcoal Grilled</a></li>
<li><a href="?link=4" name="link4" title="View all Chef's Special">Chef's Special</a></li>
</ul>
</section>
then the main file is (food-menu.php :)
<?php
include ('includes/header.html');
$link = $_GET['link'];
if ($link == '1'){
include 'html/cold-starters.html';
}
if ($link == '2'){
include 'html/hot-starters.html';
}
if ($link == '3'){
include 'charcoal-grilled.html';
}
if ($link == '4'){
include 'chef-special.html';
}
include ('includes/menufooter.html');
?>
the retrieving of file works, but how do i setup a default include page? like setup the ('html/cold-starters') to be the first page when they go to the food-menu.php url? because so far ive only included the header and footer but not a default content page.
Thanks Experts! :)
Upvotes: 0
Views: 293
Reputation: 167182
You can amend your code this way:
$link = isset($_GET['link']) ? $_GET['link'] : 1;
What happens here is, if you have given the parameter of link, it takes it, else, it will take the default value of 1
.
Upvotes: 1