Skip to: content, navigation

Advanced Syndication

This document describes advanced techniques for syndicating listings from the SitePoint Marketplace, which offer more flexibility and control over the include method and output code.

IFRAME implementation

The JavaScript implementation uses a script that generates an iframe, but you can bypass the script dependency and use a static iframe directly. This may have SEO benefits because it makes frequently-updated content available to search-engine robots, and of course it makes the content accessible to users who don't have JavaScript.

To use this technique you must pass an output parameter in the iframe src, with the value html:

<iframe src="http://marketplace.sitepoint.comhttp://marketplace.sitepoint.com/syndicate?af=AFFILIATE_ID&output=html"
	 width="250" height="500" frameborder="0" scrolling="auto"></iframe>

This parameter instructs the syndication script to output an HTML page, instead of JavaScript. The same styling parameters are available with this techniques as with the simple script technique.

Content-only implementation

If you want more control over the output styling, you may prefer to use a server-side script to retrieve the listings HTML and output it directly into your page.

To use this technique, you need to pass the output=html parameter, as with the IFRAME technique, and also a fullpage parameter with the value 0. This parameter instructs the syndication script to return only the content HTML rather than a complete HTML page:

http://marketplace.sitepoint.comhttp://marketplace.sitepoint.com/syndicate?af=AFFILIATE_ID&output=html&fullpage=0

Here's a code example using PHP to retrieve and output the content HTML:

<div id="sitepoint-listings">
<?php
$ch = curl_init();
$pageurl = 'http://marketplace.sitepoint.comhttp://marketplace.sitepoint.com/syndicate'
	. '?af=AFFILIATE_ID&output=html&fullpage=0&heading=2';
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $pageurl);
$content = curl_exec($ch);
curl_close($ch);

echo $content;
?>
</div>

The returned HTML includes two levels of headings, so in order to preserve a semantically valid headings structure on your page you can define the top-level heading number, using the heading parameter. Specify a number between 1 and 5; for example, a value of 2 will output an <h2> top-level heading.

None of the styling parameters are available with this technique, but you don't need them — you have full control over the output styling because the content is on your page.

JSON implementation

You can also use the output parameter to request that the listings information is returned in the form of JSON (JavaScript Object Notation) data. If you use this technique then you must also include a callback parameter that specifies the name of a callback function, to which the returned JSON object will be passed.

Here's a basic code example that gets the listing data, and expands it into text content so you can see what the object contains:

<textarea rows="15" cols="50" id="jsondata"></textarea>

<script type="text/javascript">
<!--

function showJSON(json)
{
	 var str = '', area = document.getElementById('jsondata');
	 for(var i in json)
	 {
		  if(typeof json[i] == 'function')
		  {
				continue;
		  }
		  if(i == 'entries')
		  {
				str += i + ':\n';
				for(var j=0; j<json.entries.length; j++)
				{
					 str += '\t' + j + ':\n';
					 for(var k in json.entries[j])
					 {
						  if(typeof json.entries[j][k] == 'function')
						  {
								continue;
						  }
						  str += '\t\t' + k + ': ' + json.entries[j][k] + '\n';
					 }
				}
		  }
		  else
		  {
				str += i + ': ' + json[i] + '\n';
		  }
	 }
	 area.value += str;
}

//-->
</script>

<script type="text/javascript"
	src="http://marketplace.sitepoint.comhttp://marketplace.sitepoint.com/syndicate?af=AFFILIATE_ID&output=json&callback=showJSON">
</script>

XML implementation

Finally, for the greatest control and flexibility, you can retrieve the listings as raw Atom feeds. These feeds are available independently of the syndication script, at the following URLs:

  • http://marketplace.sitepoint.comhttp://marketplace.sitepoint.com/feed (all categories)
  • http://marketplace.sitepoint.comhttp://marketplace.sitepoint.com/premium-upgrades/feed (premium upgrades)
  • http://marketplace.sitepoint.comhttp://marketplace.sitepoint.com/categories/premium-sites-for-sale/feed (single category; replace premium-sites-for-sale with the category key you want)

Index of advanced parameters