Jump to content

How can I best allow users to syndicate my content with one line of code?


twebman84

Recommended Posts

I want to offer my site visitors the opportunity to use some of my content on their sites. For example, a Quote of the Day or This Date in History snippet that they can place on their site. I want to host and manage the content on my site and allow the visitors to syndicate it on their sites easily. The key word here is "easily". I don't want to do this through RSS, which can be tricky for entry-level webmasters and bloggers. I want to be able to offer a line of code, say in Javascript, that the visitor can copy and paste into their site (Wordpress widget etc.) and have my content appear there.

 

Does anyone have any starting points for how to do this? I have several years of experience with PHPP, MySQL, CSS, HTML, etc., but I don't want to re-invent the wheel. I've done something similar in JSP, but not using PHP.

Link to comment
Share on other sites

You could try something as simple as a dynamic PHP file which is served with Javascript headers that your users can add to their website.  Something like:

 

<?php
$daily_quote = get_daily_quote();  # assume this is a simple string
header('Content-type: application/javascript');
?>
// The output of this page should be treated as javascript by the user's browser
(function (quote){alert(quote)})(<?php echo $daily_quote; ?>);

 

Your users then just need to hotlink the JavaScript file (really PHP) hosted on your server:

<script type="text/javascript" src="//yourserver.com/daily_quote_javascript.php"></script>

 

When the code above is interpreted by the browser, the anonymous function will just alert the quote for the day (which was determined dynamically via PHP).  You'd obviously want your function to do something more advanced like wrap the quote in appropriate HTML and add it to the page but that's up to you.

 

There are more advanced ways to approach this so if you bump into any walls or limitations with this approach, you could look into JSONP.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.