Log in

View Full Version : Dynamic a href in HTML - Help



me_myself
12-08-2008, 07:39 PM
I am working on a large static website (xHTML) - i need to know if there is a way to have the links in the "a href" tags dynamic - i.e., something like an xml file - if i change it in one place, it should get reflected all over the site. This is a static html website - please help.

Thanks.

Snookerman
12-08-2008, 08:47 PM
You can use php include for this:

<?php
include('http://www.me-myself.com/externalcode.txt');
?>
Put that code where you want it to be displayed.
externalcode.txt file:

<a href="http://www.dynamicdrive.com/">DD</a>

Of course you could use javascript or inline frames for this as well.

me_myself
12-08-2008, 08:56 PM
Should it only be a php include? Is there anything like a html include - cause i dont think i can convert all the pages to php (php includes will work only if i convert the pages to php - right?).

Please let me know if there is anything like a html or a txt file include - that would make my life a whole lot better :)

Snookerman
12-08-2008, 09:13 PM
You can still use include in html files. All you need to do is add this to your .htaccess file:

#RemoveHandler .html .htm

#AddType application/x-httpd-php .php .htm .html

AddHandler application/x-httpd-php .html .htm

If you don't have a .htaccess file you can just open Notepad and add that code in the blank page and save it as .htaccess (not file.htaccess or anything else, just .htaccess). Upload the .htaccess file to your server and you're good to go with the include.

me_myself
12-08-2008, 09:16 PM
Snookerman, thanks a lot for the reply. One more question - should i have one include (html) files for one link or can i have one include for all the link and in that html have links for all the a href items?

Thanks

Snookerman
12-08-2008, 09:35 PM
You can pretty much include anything: plain text in a .txt file, a .html page, images, .asp, sounds, etc. That's what makes include so great.
So you can put the whole part of your website that you wish to update into the .txt file.

me_myself
12-08-2008, 10:26 PM
Thanks for the very useful info.

me_myself
12-08-2008, 10:40 PM
snookerman, what would be the syntax if i used a html or a txt file as an include?

I tried <!-- #include virtual="filename.html" --> but it doesn't work.

Thanks

Snookerman
12-10-2008, 12:35 PM
Have you tried this:


<?php
include('filename.html');
?>

me_myself
12-10-2008, 03:31 PM
After having this php include, the file name should be changed to filename.php or can it be filename.html?

Thanks

Snookerman
12-10-2008, 05:07 PM
Like I said before, you can include almost anything so you don't need to change the name of the file you are including. If you mean the name of the file which has this code, then you can use the .htaccess code I wrote before to be able to have the php code in html files.

me_myself
12-10-2008, 05:11 PM
thanks a lot my friend :D

Medyman
12-11-2008, 04:38 AM
For others coming across this thread, a small clarification/rephrasing...

The solution that Snookerman suggests basically tells the server to parse your HTML files through the PHP handler. This means that you can add PHP code within your HTML files. So, the .htaccess rule takes away the necessity to have a .php extension. This is useful if you're not at liberty to rename all of your website files.

Cubikated
06-18-2010, 10:26 PM
Hi guys,

Can I used the HTML markup below, save it as highslidegallery.html or highslidegallery.php and include inside a <td> using

<?php
include('/highslidegallery.html');
?>

I'm new to web design and would appreciate any expert comments/help.

Basically I have four "mini-galleries" on my gallery page and the page is infinite with the HTML mark up. All I want is to keep it nice and tidy, and if possible link/load it externally/dynamically using PHP. Can this be achieved?

Thanks for your time. Much appreciated.


<div class="highslide-gallery">
<a id="thumb1"href="highslide/images/1.jpg" class="highslide"
title="This is just an image"
onclick="return hs.expand(this, config1 )">
<img src="highslide/images/1thumb.jpg" alt=""/>
</a>
<div class="hidden-container">
<a href="highslide/images/2.jpg" class="highslide"
title="Caption from the anchor's title attribute"
onclick="return hs.expand(this, config1 )">
<img src="highslide/images/2thumb.jpg" alt=""/>
</a>
<a href="highslide/images/3.jpg" class="highslide"
title="Caption from the anchor's title attribute"
onclick="return hs.expand(this, config1 )">
<img src="highslide/images/3thumb.jpg" alt=""/>
</a>
<a href="highslide/images/4.jpg" class="highslide"
title="Caption from the anchor's title attribute"
onclick="return hs.expand(this, config1 )">
<img src="highslide/images/4thumb.jpg" alt=""/>
</a>
<a href="highslide/images/5.jpg" class="highslide"
title="Caption from the anchor's title attribute"
onclick="return hs.expand(this, config1 )">
<img src="highslide/images/5thumb.jpg" alt=""/>
</a>
<a href="highslide/images/6.jpg" class="highslide"
title="Caption from the anchor's title attribute"
onclick="return hs.expand(this, config1 )">
<img src="highslide/images/6thumb.jpg" alt=""/>
</a>
<a href="highslide/images/7.jpg" class="highslide"
title="Caption from the anchor's title attribute"
onclick="return hs.expand(this, config1 )">
<img src="highslide/images/7thumb.jpg" alt=""/>
</a>
<a href="highslide/images/8.jpg" class="highslide"
title="Caption from the anchor's title attribute"
onclick="return hs.expand(this, config1 )">
<img src="highslide/images/8thumb.jpg" alt=""/>
</a>
<a href="highslide/images/9.jpg" class="highslide"
title="Caption from the anchor's title attribute"
onclick="return hs.expand(this, config1 )">
<img src="highslide/images/9thumb.jpg" alt=""/>
</a>
<a href="highslide/images/10.jpg" class="highslide"
title="Caption from the anchor's title attribute"
onclick="return hs.expand(this, config1 )">
<img src="highslide/images/10thumb.jpg" alt=""/>
</a>
<a href="highslide/images/11.jpg" class="highslide"
title="Caption from the anchor's title attribute"
onclick="return hs.expand(this, config1 )">
<img src="highslide/images/11thumb.jpg" alt=""/>
</a>
</div>
</div>

azoomer
06-18-2010, 11:06 PM
Cubikated ! Yes you can do that. If you save your frontpage as index.php you can include the images as Snookerman said with something like this

<?php
include('highslidegallery-1.html');
?>
And you can include several more image arrays the same way other places on your page. I am assuming it's your frontpage but you can do it with any page as long as it has php extension. Snookerman mentions .htacces but you dont need to mess with that as long as you save the page as .php.

Cubikated
06-19-2010, 01:46 PM
Hummmmmm....now that's a problem cos I have all my pages as .html

How do I convert all my pages to .php without loosing any thing?

Do I have to install something like WampServer?

azoomer
06-19-2010, 01:55 PM
Do you need the image galleries on many pages ?
If yes, then you can change the .htacces as Snookerman explains and that way avoid having to change to php extension. If you only need the imagegalleries on one or two pages then just save it as .php instead of html. You don't loose anything that way. You can't see .php pages locally as a default so either you have to upload to a server online or you can install wampserver, as you say, and run it from there.

Cubikated
06-19-2010, 02:45 PM
Thank you very much for that. I've successfully converted all my pages to .php by just renaming in Dreamweaver. Had to go through another YouTube tutorial on how to install WampServer and how to define a php site in Dreamweaver. Success again :)

Now I need to try the "include" function and see if I can get it to work.

My brain's overworked......need a holiday soon!!!! :D

Cubikated
06-19-2010, 09:12 PM
Hi azoomer,

Just a quick question.

As I said before I converted all my .html to .php in Dreamweaver and the page looks exactly like before. I'm just wondering if I should add a


<?php

<html>
<head>
<title></title>
</head>
<body>


</body>
</html>

?>

and just add anywhere I want

include('highslidegallery-1.html'); (keeping in mind that I've added the <?php ?> before and after the <html> </html> tags)

or do I have to add each time

<?php
include('highslidegallery-1.html'); (keeping in mind that I've added the <?php ?> before and after the <html> </html> tags)
?>

where I want to include the file.

Thanks for your help, much appreciated!!!!

azoomer
06-19-2010, 09:20 PM
you should add it with each include and not around the html tags.

Cubikated
06-19-2010, 10:11 PM
Thank you very much again!!!!! Good night.