Results 1 to 7 of 7

Thread: PHP and DD Scripts

  1. #1
    Join Date
    Jun 2005
    Location
    Canada
    Posts
    68
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default PHP and DD Scripts

    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

  2. #2
    Join Date
    Jun 2007
    Posts
    72
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default

    Do you mean something like:

    PHP Code:
    <? include 'menu.php'?>
    Just place that code where you want your menu to show on the page.

  3. #3
    Join Date
    Jun 2005
    Location
    Canada
    Posts
    68
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    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

  4. #4
    Join Date
    Jun 2007
    Posts
    72
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default

    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
    PHP 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.

  5. The Following User Says Thank You to calumogg For This Useful Post:

    Diversions (04-12-2008)

  6. #5
    Join Date
    Jun 2005
    Location
    Canada
    Posts
    68
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Makes perfect sense.
    Thank you for your help

  7. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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 Code:
    <?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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #7
    Join Date
    Jun 2005
    Location
    Canada
    Posts
    68
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •