Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    som
    som is offline
    New Coder
    Join Date
    Dec 2009
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Need to make Dynamic Links(example shown)

    I need to make an dynamic editable links box which I can put on every page of my website, but instead of having to change the links manually I can just do it to one source file, and the box will display that.

    I want to do it in a way very similar to how if you link all of the pages on your site to 1 css file, you can make the style changes site wide just by editing that one css file.



    This is how the box will look:

    http://tvomic.com/index.html

    so where the text Editable Link #1 is shown, instead whatever the source file says the first link is will display.


    I need to make it so the editable source file, which will control what the box displays sitewide, will work like
    <a href="(insert hyperlink)"> (insert text)</a>
    <a href="(insert hyperlink)"> (insert text)</a>
    <a href="(insert hyperlink)"> (insert text)</a>
    <a href="(insert hyperlink)"> (insert text)</a>
    <a href="(insert hyperlink)"> (insert text)</a>
    <a href="(insert hyperlink)"> (insert text)</a>

    or somehow so all I do is insert the 6 different hyperlinks, upload the file to my site, and then the box will display this site wide.
    then when I will update my site again I can just easily do this again using the same method, only just replacing the old links in the source file with the new ones.

    I have thousands of pages, so I need to make so



    In the end product, I need something
    Just like "recent Posts" box on this site:
    http://fastonlinetvs.co.tv/

    The only problem is my site is in html so I don't think wordpress will work (which is what they use).

  • #2
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    628
    Thanks
    51
    Thanked 67 Times in 67 Posts
    Wordpress is done in PHP. It is not necessary to use Wordpress (as it is just a framework), but you do need PHP (or any other related language) to use the include command. Most hosting plans support either PHP or ASP (there are other languages you can use, but those are the two most popular). If they don't, you could use the Javascript document.write command and external file linking. You won't be making an HTML page (which you could do if you were using PHP), rather you'd simply be printing out HTML with javascript in a javascript page. Again, though, just about all webhosts support PHP, and in a PHP file all you need is <?php include('myfile.html') ?> and myfile.html (where your navigation will be contained) will be implanted into your page. I was actually using php includes for a while before I actually learned and started using PHP.
    "Yeah science!"

  • #3
    som
    som is offline
    New Coder
    Join Date
    Dec 2009
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Do you think you could guide me so I can set this up?
    I have no idea how to use php, could you copy and paste the php source file code here, then I will upload it to my site?



    the host is hostgator.

    So if 6 links I wanted were

    <a href="http://www.google.com"> Google</a>
    <a href="http://www.yahoo.com""> Yahoo</a>
    <a href="http://www.aol.com""> AOL</a>
    <a href="http://www.msn.com""> MSN</a>
    <a href="http://www.facebook.com""> Facebook</a>
    <a href="http://www.youtube.com""> Youtube</a>

    how would I turn that into a PHP file, which I could then link to index.html?

  • #4
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    628
    Thanks
    51
    Thanked 67 Times in 67 Posts
    All you have to do is save all your html files as .php instead of .html. You will then be able to place php code into your script. You won't be able to open up your files directly anymore, though, as PHP is a server side language and needs to be able to communicate with a server that supports it and will have to upload them to test them.

    Inside your PHP file, <?php is used to start a php statement and ?> is used to end it (similar to HTML tags, except if you make a syntax error in PHP you will get a fatal error on your page where in HTML it might not even seem to make a difference). include('myfile.html'); will include the indicated file. What include does is take that file and inserts it into your file (since PHP is server side, it does all this before it outputs the final result). Here's an example code:

    yourfile.php
    PHP Code:
    <html>
    <head>
    <title>My Page</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <h1>This is my page</h1>
    <?php
    include('navigation.html');
    ?>
    <p>This is a paragraph. Lalala.</p>
    </body>
    </html>
    navigation.html
    Code:
    <a href="somepage.php">Page 1</a><br>
    <a href="someotherpage.php">Page 2</a>
    yourfile.php (the final output):
    PHP Code:
    <html>
    <
    head>
    <
    title>My Page</title>
    <
    link href="styles.css" rel="stylesheet" type="text/css" />
    </
    head>
    <
    body>
    <
    h1>This is my page</h1>
    <
    a href="somepage.php">Page 1</a><br>
    <
    a href="someotherpage.php">Page 2</a>
    <
    p>This is a paragraphLalala.</p>
    </
    body>
    </
    html
    As you can see, the PHP has been processed by the server and is not displayed in the final output. An important thing to remember is that the page loaded is the important page. What I mean by that is that if your navigation file is in a separate folder and it has a link in it, the link will search the directory of the main page (if navigation.html is in folder2 and yourfile.php is in folder1 and you have a link in your navigation to somepage.php, the link will go to folder1/somepage.php). If you'd like to know more about PHP or server side scripting, there's a lot of good tutorials out there, my favorite being http://tizag.com.
    "Yeah science!"


  •  

    Posting Permissions

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