• home
  • forum
  • my
  • kt
  • download
  • Offering Automatically Updating Syndicated Articles

    Author: 2007-08-06 09:50:01 From:

    Articles are a popular form of syndicated content. They are often offered out for manual syndication - the article is simply displayed with a notice stating that it can be reprinted once the required terms are met. There is another popular format though - automatically updating articles.

    This tutorial explains an easy method of offering an automatically updated html file to other sites. I have taken the example of an article but the same theory could be applied to other content such as tutorials, images or news.

    Step One

    You need to decide upon a name and location for the file you will be offering out. This is because you will be giving the sites that add your content to theirs a simple line of JavaScript to add to their page and call your file. This will mean no effort on their part once they have added the JavaScript to their site. A little regular effort on your part will be required in that you will need to update this file weekly or at whatever other interval you have decided upon.

    For example I have decided to call my file weeklyarticle.js and place it in a folder called examples that I keep in my root directory. You can call your file whatever you like but please note that your file must have a JavaScript (.js) file name extension.

    The URL of my example file would be http://www.purplepages.ie/examples/weeklyarticle.js

    Once you have the URL of your file you can work out what the JavaScript you need to give to your syndicating sites will be. In my case I would use the following JavaScript:

    <script language="JavaScript" src="http://www.purplepages.ie/examples/weeklyarticle.js">
    </script>

    Yours will be the same, only referring to the URL of your file rather than http://www.purplepages.ie/examples/weeklyarticle.js

    Step Two

    In the second part of this tutorial I explain how to create a file for syndication.

    You must remember that this file will be displayed on other people's sites and code with this in mind.

    You cannot use relative URLs

    E.g. what you may be used to referring to as /images/logo.gif needs to be referred to as a full URL like http://www.mydomain.com/images/logo.gif

    What you can and cannot use in your file

    You cannot use ASP, PHP or any other technologies that may not be available on other sites' servers - this is likely to cause errors on your syndicating site's pages.

    You are safe using any HTML once you remember it is being accessed from somewhere else and use full URLs.
    You can also use CSS once you include it all in your file rather than call a file on your server. Some but not all JavaScript can be used, so make sure you test your use of any. If you are including forms that utilize CGI programs, make sure those programs allow input from domains other than your own.

    It is often a good idea to leave the formatting of your HTML reasonably plain so your syndicating sites can use their own style sheet, that suits the look and feel of their site.

    Making your HTML file JavaScript compatible

    You will now need to make your file JavaScript compatible before you upload it. This is a little difficult to begin with but you will soon get the hang of it.

    There are six points to remember

    • Insert this as the first line of your file: <!--
    • Insert this as last line of your file: //-->
    • Precede every backslash \ with another backslash: \\
    • Precede every apostrophe ' with a backslash: \'
    • Except for the first and last lines, end each line with: ');
    • Except for the first and last lines, begin each line with:
       document.writeln('

    Once you upload your file every syndicating site calling your JavaScript is automatically updated.

    A working example is available in part two of this article.

    A Working Example

    As already explained, my example file is called weeklyarticle.js and is located in a folder called examples that I keep in my root directory.

    My syndicating sites would be adding the following to their pages, wherever they would like my article to appear:

    <script language="JavaScript" src="http://www.purplepages.ie/examples/weeklyarticle.js">
    </script>

    You can add this code into a HTML file and test it yourself. I have also uploaded a file containing this code, which you can view here.

    Weekly Article

    For the purposes of this example my weekly article is going to be a short money-saving travel tip, as below:

    This Week - Spotlight on Tunisia

    Tunisia

    If you are traveling to Tunisia this year be sure to bring some whiskey with you. Whiskey is very hard to come by in Tunisia and will be greatly appreciated by the locals - you can even barter with it in the many shops and markets.

    The HTML for the above would be:

    <b>This Week - Spotlight on Tunisia</b><br>
    <img src="http://www.purplepages.ie/site/graphics/tunisia.jpg" width="128" height="85" border="0" alt="Tunisia"><br>
    If you are traveling to Tunisia this year be sure to bring some whiskey with you. Whiskey is very hard to come by in Tunisia and will be greatly appreciated by the locals - you can even barter with it in the many shops and markets.<br>

    Making the HTML JavaScript compatible would result in:

    < !--
    document.writeln('
    <b>This Week - Spotlight on Tunisia</b><br>');
    document.writeln('
    <img src="http://www.purplepages.ie/site/graphics/tunisia.jpg" width="128" height="85" border="0" alt="Tunisia"><br>');
    document.writeln('

    If you are traveling to Tunisia this year be sure to bring some whiskey with you. Whiskey is very hard to come by in Tunisia and will be greatly appreciated by the locals - you can even barter with it in the many shops and markets.<br>');
    //-->


    Any changes are marked in green. The above is the code I have uploaded as weeklyarticle.js for this example.

    Previous Page

    Author: Alis Marsden is a staff writer for Purple Pages.

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      AJAX (20)
      Content Management (7)
      Cookies (4)
      Date and Time (12)
      Development (7)
      DHTML (14)
      Forms (8)
      Frequently Asked Questions (1)
      Image Display (9)
      Introduction to Javascript (5)
      Links and Buttons (4)
      Menus (2)
      Miscellaneous (5)
      Mouse Tricks (3)
      Navigation (8)
      Randomizing (4)
      Security (1)
      Text Effects (6)
      User Authentication (2)
      User Information (5)
      Windows and Frames (3)

    New

    Hot