View Full Version : PHP and DD Scripts
Diversions
04-12-2008, 01:28 PM
As I transition from Front Page to real web site development, I have a very elementary question regarding PHP and the scripts available from Dynamic Drive. When I have a number of php pages (index, column_left, column_right, header. footer et al numbering a couple of hundred) and the DD script has a code that is to be inserted into the page in which the script is to appear, where do I place that code (aside from the <head></head>)if I want it to be universally shown throughout the entire site? Right now I am specifically looking at a Dynamic Menu script that will slide in from the left but there are sure to be more coming scripts used as I find my way.
I hope this question makes some sense.
Thanks
D
calumogg
04-12-2008, 02:29 PM
Do you mean something like:
<? include 'menu.php'; ?>
Just place that code where you want your menu to show on the page.
Diversions
04-12-2008, 03:11 PM
Okay, specifically with the DD Dynamic-FX Slide in menu (v 6.5) script that floats along the left edge of the page so there is not a fixed position. There are two .js files that need to be coded and uploaded to the site (even my limited knowledge can handle that part) but it is the following code that is to be added "into the <head> section of your page"
So the question is in PHP pages where there is no ONE page but a collection of page elements into which page do I place this? the main index.php page or the column_left.php page or every page on the site to ensure its presence.
<style type="text/css">
<!--
A.ssmItems:link {color:black;text-decoration:none;}
A.ssmItems:hover {color:black;text-decoration:none;}
A.ssmItems:active {color:black;text-decoration:none;}
A.ssmItems:visited {color:black;text-decoration:none;}
//-->
</style>
<SCRIPT SRC="ssm.js" language="JavaScript1.2">
//Dynamic-FX slide in menu v6.5 (By maXimus, http://maximus.ravecore.com/)
//Updated July 8th, 03' for doctype bug
//For full source, and 100's more DHTML scripts, visit http://www.dynamicdrive.com
</SCRIPT>
<SCRIPT SRC="ssmItems.js" language="JavaScript1.2"></SCRIPT>
Thanks for your help on this calumogg
D
calumogg
04-12-2008, 03:26 PM
If you make a PHP page called menu (or what ever you want) copy the complete menu script into the menu.php file, then in all the pages on your site use the code
<? include 'menu.php'; ?>
that will load the menu, so then just copy the include code onto every page you want the menu to load on.
Diversions
04-12-2008, 03:32 PM
Makes perfect sense.
Thank you for your help
djr33
04-12-2008, 09:53 PM
PHP created pages behave no differently than pure html pages. The difference is that it can become a maze to find where a particular section is generated, or even impossible to alter part of the page which has already been output.
The method above works, but you might run into a situation where you're still confused.
First:
Look through your PHP, all the layers of includes, and find where that section is generated. That's step one.
Second:
If you do find that you cannot access the head section, it may be time to reorganize your script. In most basic terms, you'll be creating a templating system. You will make the very end of your script all the output (Doctype through </html>), and everything above will be saved into variables to be output later. As a simplistic example:
<?php
$head = '<script>....';
$body = 'hello visitors!';
?>
<!Doctype.....>
<html>
<head>
<?php echo $head; ?>
</head>
<body>
<?php echo $body; ?>
</body>
</html>
Of course that won't be too much help in all cases and a real site might have dozens of variables. You might want to change the properties in the body tag so you can have <body <?php echo $bodytagextra; ?>>, which could include an onload event or a background color, though with a complex site I'd suggest trying to move these to external CSS/JS files.
And on that note, it's a good idea to try to move all CSS styles and JS to external files. Remember the only difference is in how it's accessed, not the code itself, so just grab the code, stick it in .css or .js respectively, then include it as an external file rather than writing it to the page. That will make it a lot easier to change.
(Now if you have a style that only affects one page, this is where you would want to write it directly to the head section, in addition to any existing stylesheet(s).)
Overall, remember the purpose of PHP: To generate html. It goes through your code systematically and in the end outputs html as you desire. So basically it's helping you write each page. Now you just need to go through extremely carefully to find exactly what part of the code affects exactly what part of the output, and it won't be too hard to adjust how it works.
Diversions
04-12-2008, 10:08 PM
In the past three months I have been pouring through tutorials and trying to get my head around this (bearing in mind I am not nearly a young and agile mind any longer) and that is the best explanation I have heard.
Thank you djr33 - most helpful and I think I am beginning to understand
Cheers
D
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.