Zend - The PHP Company




External

Add Code


Get TemplateMonster data  

Type: code fragment
Added by: olaflederer
Entered: 17/03/2005
Last modified: 03/12/2004
Rating: - (fewer than 3 votes)
Views: 4273
This is an simple example about how to get data from templatemonster's webapi to your website while using PHP (only). Of course this is not the most common way but it works if the execution time is not the most important factor. Try the demo link and see how it works.


<?php
// For more information: visit http://www.templatemonster.com/webapi/
$num_records 4
$aff_link "http://www.all4yourwebsite.com/";
$tm_url "http://www.templatemonster.com/";
$tm_url .= "webapi/templates_screenshots4.php";
$param['last_added'] = "Yes"// this value is case sensitive
$param['full_path'] = "true";
$param['order'] = "asc";
$param['sort_by'] = "date";
$param['filter'] = "1";
// add additional filters / parameters here
// building querystring from the parameters
$qs "?";
foreach (
$param as $key => $val) {
    
$qs .= $key."=".$val."&";
}
$qs rtrim($qs"&");
// now get the records from the TM webapi
$request_from $tm_url.$qs;
$all_rows file($request_from);
// now split the data for each row into an multi dim. array
for ($i 0$i $num_records$i++) {
    
$data[$i] = explode("t"$all_rows[$i]);
}
$t_row "<div id="thumbs">n";
foreach (
$data as $row) {
    
// read the information about more attr.
    
$id $row[0];
    
$price $row[1];
    
$all_images explode(","trim($row[15], "{}"));
    
$t_row .= "  <div class="thumb">n";
    
$t_row .= "    <div class="box">n";
    foreach (
$all_images as $img) {
        if (
preg_match("/-m.jpg$/"$img)) {
            
$thumb $img;
        }
    } 
    
$thumb_size getimagesize($thumb);
    
$t_row .= "      <a href="".$aff_link."" target="_blank">";
    
$t_row .= "<img src="".$thumb."" ".$thumb_size[3]." border="0" alt="template no".$id."">n";
    
$t_row .= "</a>n";
    
$t_row .= "    </div>n";
    
$t_row .= "    <p>Price: $".$price."</p>n";
    
$t_row .= "  </div>n";
}
$t_row .= "</div>";
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories