+ Post New Thread
Results 1 to 13 of 13
Web Development Thread, Joomla - editing the head of individual pages? in Coding and Web Development; I've come across a problem over the past couple of days because of several scripts I want to use. These ...
  1. #1

    Join Date
    May 2006
    Posts
    1,319
    Thank Post
    101
    Thanked 25 Times in 18 Posts
    Rep Power
    25

    Joomla - editing the head of individual pages?

    I've come across a problem over the past couple of days because of several scripts I want to use. These scripts unfortunately involve placing code in the head section of the page, yet they are only required on one page each. Joomla it appears only allows you to edit the head for every single webpage on the site. This is very limiting so I am sure there must be a way to add code to the head of just one page only?

    Does anyone know of a way of doing this, or a work around?

    Thanks

    James

  2. #2
    Irazmus's Avatar
    Join Date
    Feb 2006
    Location
    Suffolk
    Posts
    315
    Thank Post
    13
    Thanked 22 Times in 17 Posts
    Rep Power
    23

    Re: Joomla - editing the head of individual pages?

    You could always add a conditional statement in the head of the template file.

    Code:
    <? if ($_GET['option'] == 'com_contact') { ?>
        <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=YOUR_KEY" type="text/javascript"></script>
            <? } ?>
    I use this to imbed Google Maps on the contact page without having to call an external script on every page.
    It may not be the most elegant solution, but it works and puts very little extra strain on the server.

  3. #3

    Join Date
    May 2006
    Posts
    1,319
    Thank Post
    101
    Thanked 25 Times in 18 Posts
    Rep Power
    25

    Re: Joomla - editing the head of individual pages?

    Quote Originally Posted by Irazmus
    It may not be the most elegant solution, but it works and puts very little extra strain on the server.
    I considered doing this, but I have about 16 or 17 pages that each need a seperate piece of code in the head. Would this still be considered to not be putting much extra strain on the server? Thats rather a lot of code when multipled by 17

  4. #4

    Join Date
    May 2006
    Posts
    1,319
    Thank Post
    101
    Thanked 25 Times in 18 Posts
    Rep Power
    25

    Re: Joomla - editing the head of individual pages?

    I'll just clarify what I am trying to do. I am doing image rollovers on these 16/17 pages, all with different images. This means different code in the head for each page, mainly for the preload of the images. I don't think there is any way of avoiding putting the code into the head.

  5. #5

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    640
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324

    Re: Joomla - editing the head of individual pages?

    Each page you want to include as a separate file?

    Code:
    $option = $_GET['option'];
    $file = "includes/$option.php";
    if(file_exists($file)){
      include($file);
    }

  6. #6

    Join Date
    May 2006
    Posts
    1,319
    Thank Post
    101
    Thanked 25 Times in 18 Posts
    Rep Power
    25

    Re: Joomla - editing the head of individual pages?

    Quote Originally Posted by webman
    Each page you want to include as a separate file?

    Code:
    $option = $_GET['option'];
    $file = "includes/$option.php";
    if(file_exists($file)){
      include($file);
    }
    I'm a little bit lost :?

  7. #7

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    640
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324

    Re: Joomla - editing the head of individual pages?

    Sorry, my mistake... didn't know exactly how the Joomla URLs worked ops:

    Ok, each page has an ID, so you get the ID from the URL and then look for a file in includes/$id.php - where you make a single file for each page (id) you want that has the information you want to display. The PHP includes the right file for the page.

    Code:
    $id = $_GET['id'];
    $file = "includes/$id.php";
    if(file_exists($file)){
      include($file);
    }

  8. #8
    Irazmus's Avatar
    Join Date
    Feb 2006
    Location
    Suffolk
    Posts
    315
    Thank Post
    13
    Thanked 22 Times in 17 Posts
    Rep Power
    23

    Re: Joomla - editing the head of individual pages?

    Quote Originally Posted by _Bat_
    I considered doing this, but I have about 16 or 17 pages that each need a seperate piece of code in the head. Would this still be considered to not be putting much extra strain on the server? Thats rather a lot of code when multipled by 17
    The extra strain would come more from the 16 extra IF statements rather than the quantity of code, but you could get around that by using a SWITCH statement which would be more efficient.
    However Webman's approach is probably better, not simply for the server but also for you when you have to modify it later.

  9. #9

    Join Date
    May 2006
    Posts
    1,319
    Thank Post
    101
    Thanked 25 Times in 18 Posts
    Rep Power
    25

    Re: Joomla - editing the head of individual pages?

    Quote Originally Posted by webman
    Sorry, my mistake... didn't know exactly how the Joomla URLs worked ops:

    Ok, each page has an ID, so you get the ID from the URL and then look for a file in includes/$id.php - where you make a single file for each page (id) you want that has the information you want to display. The PHP includes the right file for the page.

    Code:
    $id = $_GET['id'];
    $file = "includes/$id.php";
    if(file_exists($file)){
      include($file);
    }
    Okay I understand that now. Just one more question and I know its really simple but I was never any good with PHP.

    There is also an onload function in the body tag, so on the pages that use the image rollovers, the body tag would have to be modified. I thought the easiest way of doing this is to do an ELSE statement at the end of your code, i.e. IF file exists, include it, ELSE insert "</head><body>". That way, I could include the modified body tag in the $id.php for the pages that need it.

    I would do this myself, but as I say, I was never any good with PHP, i'm trying to learn it though. Is it possible you could show me how?

    Thanks for all your help, both of you.

    James

  10. #10

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    640
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324

    Re: Joomla - editing the head of individual pages?

    Put customised body tags in the individual files:

    inclues/45.php (example)

    Code:
    <?php
    $body = '<body onload="image_function()">';
    echo '(other stuff for this page)';
    ?>
    And once it's included:

    Code:
    <?php
    if(isset($body)){
      echo $body;
    } else {
      echo '<body>';
    }
    If the $body variable exists (set in your included files) then just echo it out; otherwise just print a bog-standard tag without any onload things.

  11. #11

    Join Date
    May 2006
    Posts
    1,319
    Thank Post
    101
    Thanked 25 Times in 18 Posts
    Rep Power
    25

    Re: Joomla - editing the head of individual pages?

    Okay I think I did what you said, I now get the following PHP error:

    Parse error: parse error, unexpected T_STRING in /var/www/html/headincludes/12.php on line 2
    Line two is:

    $body = '</head><body onload="MM_preloadImages('images/image1.JPG','images/image2.JPG','images/image3.JPG')" class="mainpage">';
    Any ideas?

  12. #12

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    640
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324

    Re: Joomla - editing the head of individual pages?

    You will need to escape all the single quotes in the string with a backslash.

    Code:
    $body = '</head><body onload="MM_preloadImages(\'images/image1.JPG\',\'images/image2.JPG\',\'images/image3.JPG\')" class="mainpage">';

  13. #13

    Join Date
    May 2006
    Posts
    1,319
    Thank Post
    101
    Thanked 25 Times in 18 Posts
    Rep Power
    25

    Re: Joomla - editing the head of individual pages?

    Quote Originally Posted by webman
    You will need to escape all the single quotes in the string with a backslash.

    Code:
    $body = '</head><body onload="MM_preloadImages(\'images/image1.JPG\',\'images/image2.JPG\',\'images/image3.JPG\')" class="mainpage">';
    That worked . Thank you ever so much, I'll let you get on with your own job now, haha.

SHARE:
+ Post New Thread

Similar Threads

  1. Joomla menu Editing
    By gh256 in forum EduGeek Joomla 1.0 Package
    Replies: 10
    Last Post: 19th November 2007, 12:47 PM
  2. Joomla Menu Module editing and creation
    By ChrisH in forum Web Development
    Replies: 8
    Last Post: 6th July 2007, 12:16 PM
  3. Replies: 3
    Last Post: 27th April 2007, 08:32 AM
  4. Test individual access points in a dense wireless network
    By monkey_boy in forum How do you do....it?
    Replies: 8
    Last Post: 6th February 2007, 07:49 PM
  5. 'cloaking' URLS of individual Pages
    By Mintsoft in forum Web Development
    Replies: 11
    Last Post: 8th July 2006, 12:22 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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