**Foto casuale** include "/home/dneroni/carrimerci.it/cpmfetch/cpmfetch.php"; $objCpm1 = new cpm("/home/dneroni/carrimerci.it/cpmfetch/cpmfetch_config.php"); $options=array(windowtarget => “_blank” , 'imagewidth' => '150'); $objCpm1->cpm_viewRandomMedia(1,1,$options); {{stars>1/5}} {{stars>-1/5}} {{stars>2}} $base_url = "http://gallery.carrimerci.it/random/piwigo-random-backend.php"; echo file_get_contents($base_url . "?mode=html&cat_id=119"); ~~NOCACHE~~

Random image, no style

This is a random image

Specifying a category

Several images at a time

Styling the images

---- $cat_id = 119; $per_page = 2; $webapi1 = "http://gallery.carrimerci.it/ws.php?format=rest&method=pwg.categories.getImages&cat_id=$cat_id&per_page=$per_page" ; $strXml1 = file_get_contents($webapi1); $objXml1 = new SimpleXmlElement($strXml1); $piwigo = array(); $counter = 1; foreach($objXml1->images->image as $value) { $thumbs_string = strval($value->derivatives->square->url); $url_string = strval($value->categories->category->attributes()->page_url); $data_available = strval($value->categories->category->attributes()->page_url); //modify $piwigo[$counter]['thumb'] = $thumbs_string; $piwigo[$counter]['url'] = $url_string; $counter++; } foreach($piwigo as $value) { echo ' ' . '' . PHP_EOL; } ?>

DEMO OF THE WORKAROUD SOLUTION

categories->category as $value) { $count_images += $value->attributes()->total_nb_images; } echo '

Calculated total images: ' . $count_images . ' => Calculated number of pages: ' . intval($count_images/$per_page) . '

'; //start parsing the web api output with the workaround logic $per_page1 = $per_page * 2; //we need to retrive double number of specified pages because $count_images/$per_page is float number. we will slice it at the end $pages1 = intval($count_images/$per_page1); // $webapi3 = "http://gallery.carrimerci.it/ws.php?format=rest&method=pwg.categories.getImages&order=date_available&per_page=" . $per_page1 . "&page=" . $pages1; echo '

The calculated Web Api request is: ' . $webapi3 . '

'; $strXml3 = file_get_contents($webapi3); $objXml3 = new SimpleXmlElement($strXml3); $piwigo2 = array(); $counter2 = 1; foreach($objXml3->images->image as $value) { $thumbs_string = strval($value->derivatives->square->url); $url_string = strval($value->categories->category->attributes()->page_url); $piwigo2[$counter2]['thumb'] = $thumbs_string; $piwigo2[$counter2]['url'] = $url_string; $counter2++; } $piwigo2 = array_reverse($piwigo2); $piwigo2 = array_slice($piwigo2, 0, $per_page); foreach($piwigo2 as $value) { echo ' ' . '' . PHP_EOL; }