This is a PHP code that will list 5 random advertisements with images.
It requires the cyclos.php file to be included. Also, the results links to the advertisement details page.
<?php
// Get the web service proxy
require_once 'cyclos.php';
$cyclos = new Cyclos();
$adsService = $cyclos->service('ads');
//Set the parameters
$params = new stdclass();
$params->tradeType = 'OFFER';
$params->pageSize = 5;
$params->withImagesOnly = true;
$params->randomOrder = true;
//Ensure the input parameter is named 'params' and the output, 'return'
$page = $adsService->search(array('params' => $params))->return;
$ads = ensure_array($page->ads);
?>
<h1>Some advertisements</h1>
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<th> </th>
<th>Title</th>
<th>User</th>
<th>Price</th>
</tr>
<?php foreach($ads as $ad) {
$images = ensure_array($ad->images);
$image_url = empty($images) ? $no_picture_thumbnail : $images[0]->thumbnailUrl;
?>
<tr>
<td><img src="<?= $image_url ?>"></td>
<td><a href="#" onclick="window.open('view_ad_details.php?id=<?= $ad->id ?>')"><?= $ad->title ?></a></td>
<td><?= $ad->owner->name ?></td>
<td><?= $ad->formattedPrice ?> </td>
</tr>
<?php } ?>
</table>