开发者

PHP 1 element per category in RSS

Guys, i have something like this:

$rss->feed = "http://nola.gosimian.com/rss_content.php";                
        if (!$rss->parse())
              echo $rss->error;


        $column_count = 0;            
        $i=0;  
        while($i < 25)
        {       


            $title      = $rss->channel['ITEM'][$i]['TITLE'];
            $item_id        = $rss->channel['ITEM'][$i]['ITEMID'];
            $title_clean = ereg_replace("[[:space:]]", "", $title);             
            $credits    =  str_replace(' -cmd- ',',', $rss->channel['ITEM'][$i]['COMMENTS']);
            $credits_clean = str_replace(',Director||','', $credits);
            $credits_clean = ereg_replace("[[:space:]]", "-", $credits_clean);
            $desc       =  $rss->channel['ITEM'][$i]['DESCRIPTION'];
            $thumbnail  =  $rss->channel['ITEM'][$i]['SOURCE'];
            $media      =  $rss->channel['ITEM'][$i]['ENCLOSURE']['URL'];
            $date       =  $rss->channel['ITEM'][$i]['PUBDATE'];    
            foreach($date as $date) {
            echo '<a href="'.get_option('home').'/player/'.$credits_clean.'/' . $item_id . '" title="' . $title . '"><img src="' . $thumbnail . '" width="190" height="115" class="thumbnail"></a>';                       
            $column_count++;        
            $i++;           
            }
            /*if($column_count == 3)
            {
                echo '</tr><tr>';
                $column_count = 0;
            }*/

     开发者_StackOverflow   }

Is it possible to show only one item/entry of the RSS for each "Director" Element (if there are twelve directors, show twelve videos). ?

Thanks so much!!


What you could do is store the value of $credits in an array within the while loop. If you hit a credit line you've already outputted, just continue to the next element.

$creditsSeen = array();
while($i < 25) {
    ...
    $credits_clean = ...
    if (in_array($credits_clean, $creditsSeen)) {
        $i++; // perhaps you need to increment $column_count as well?
        continue;
    } else {
        $creditsSeen[] = $credits_clean;
    }
    ...
}

Disclaimer I'm not entirely sure this is what you're asking. If this is unusable in your situation, please elaborate on your question :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜