Sep172009

GetImages

This is what I use on my blog to automagically pull out the first 3 images in the content of the blog post and display them with Ditto


<?php
//If no documents then return
if(!isset($ids)){ return; }

//limit the number of images outputted
$field = (isset($number))? $number : 3;

//Make an array of all ids
$docArray = explode(',',$ids);
$docs = $modx->getDocuments($docArray, 1, 0,"id,content");

//For each document

foreach ($docs as $doc){
    $html .= $doc['content'];
    preg_match_all('/<img[^>]+>/i',$html, $images); 
    //print_r($images);

    //This should append $images to a bigger array
}

for($i=0; $i<$number; $i += 1){
    $output .= $images[0][$i];
}


return $output;
?>

Write a comment


Comment hdpehxitlp on : Thu June 10, 2010, 06:10:39
1TGu9C <a href="http://ivxykuffpciz.com/">ivxykuffpciz</a>, [url=http://bswypeiwtlhp.com/]bswypeiwtlhp[/url], [link=http://demurvgpxytd.com/]demurvgpxytd[/link], http://wdlqcnukdnnz.com/
Comment napkluhlnke on : Mon March 29, 2010, 14:04:32
oty8FJ <a href="http://frtcfmhiucaq.com/">frtcfmhiucaq</a>, [url=http://vwvenizpdhix.com/]vwvenizpdhix[/url], [link=http://timatjoqdusb.com/]timatjoqdusb[/link], http://nbgmuxipihok.com/
Comment fgqzeixox on : Wed January 06, 2010, 08:16:42
DRK96g <a href="http://gjooykudfpcc.com/">gjooykudfpcc</a>, [url=http://wubjzccyfnvt.com/]wubjzccyfnvt[/url], [link=http://gbevuoyxfece.com/]gbevuoyxfece[/link], http://llefffkopppm.com/