Simple PHP Q - include
- Started
- Last post
- 15 Responses
- moth0
A general tip dancer - stick this at the top of your file while developing;
error_reporting(E_ALL);
It'll point out the obvious errors and such.
Remove it, or better still leave it and change to this once you're live;
error_reporting(0);
- moth0
I would expect that $thisPage is not returning what you're expecting.
Try to simply echo it and see what it's returning;
echo $thisPage;
- Dancer0
Hi I have byumped this thread because the below is not placing a class in the <a> tag:
<li id="home_butt"> <a href="index.php"
title="Nosh Detox Delivery" <?php if ($thisPage=="homepage"
) echo "class=\"selected\""; ?> >Home</a></li>- Ignore me I did not realise the if statement is case sensitiveDancer
- pylon0
The server parses the code and, um, serves it as HTML, so no there's not a real dif for SEO.
Includes make reusing (and changing) common elements much faster and easier.
- Dancer0
BTW.
I have assuming that there are no disadvantages to using includes? Search Engines will just see it as normal HTML yeah?Sorry real Noob here, just had enough of adjusting every menu item for each page so I thought I would get into this :)
- Dancer0
Thanks all.
If anyone is searching for this in the future I have also found this:
http://www.alistapart.com/articl…
- pylon0
Yes.
- OhYeah0
Can't you just create a file called menu.php (no body tags ect) and then include it in your index.php using <?php include("menu.php"); ?>
- http://www.tizag.com…OhYeah
- this is what we are talking aboutmaximillion_
- maximillion_0
yeah you can
$item1Name = 'something i might get from a DB";
$selector = "current";$myVar = "
<ul >
<li class="".$selector."">".$item1Name."</li>
<li>menu item#2</li>
<li>menu item#3</li>
</ul >
";
- Dancer0
I see, so if I had a css class for a "selected" menu item I could use this?
- maximillion_0
i.e the output would be
<ul >
<li>something i might get from a DB</li>
<li>menu item#2</li>
<li>menu item#3</li>
</ul >
- maximillion_0
$item1Name = 'something i might get from a DB";
$myVar = "
<ul >
<li>".$item1Name."</li>
<li>menu item#2</li>
<li>menu item#3</li>
</ul >
";the value of $item1Name will be used as the first li elements text.
- Dancer0
thank you
- maximillion_0
if you want to add PHP vars in there (the included content) you might want to checkout heredoc syntax or use strings i.e
$myVar = "
<ul >
<li>menu item#1</li>
<li>menu item#2</li>
<li>menu item#3</li>
</ul >
";echo $myVar;
- maximillion_0
just the html if you place the include in the body tag
- Dancer
Very very simple question.
I have filtered here and found nout. I have tried google but I feel it is such a simple answer question I will get a quick response here.
Basically to use an include file how much html do I put in the file I am including? Do I need a doc type, body and html tags? or for a menu would you just need:
<ul >
<li>menu item#1</li>
<li>menu item#2</li>
<li>menu item#3</li>
</ul >