treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Help needed kinda fast for defining a previous loop output

  • I have a client using simple press forum plugin for wordpress and needs to limit the rss feed.

    Here's a relevant part:
    <?php 
    if($rssItem)
    {
    foreach($rssItem as $item)
    {
    ?>
    <item>
    <title><?php sf_rss_filter($item->title) ?></title>
    <link><?php sf_rss_filter($item->link) ?></link>
    <category><?php sf_rss_filter($item->category) ?></category>
    <guid isPermaLink=\"true\"><?php sf_rss_filter($item->guid) ?></guid>
    <description><![CDATA[<?php sf_rss_filter($item->description) ?>]]></description>
    <pubDate><?php sf_rss_filter($item->pubDate) ?></pubDate>
    </item>
    <?php
    }
    }
    ?>


    What I need to do is make sure that if the title has been outputted before it does not show again, so there is no duplicates. Any ideas?

    I was thinking of an if statment working on past outputs, but I don't know how.
  • does this work?

    <?php 
    if($rssItem)
    {
    $array = array();
    foreach($rssItem as $item)
    {
    if(!in_array($item->title,$array)){
    ?>
    <item>
    <title><?php sf_rss_filter($item->title) ?></title>
    <link><?php sf_rss_filter($item->link) ?></link>
    <category><?php sf_rss_filter($item->category) ?></category>
    <guid isPermaLink=\"true\"><?php sf_rss_filter($item->guid) ?></guid>
    <description><![CDATA[<?php sf_rss_filter($item->description) ?>]]></description>
    <pubDate><?php sf_rss_filter($item->pubDate) ?></pubDate>
    </item>
    <?php

    array_push($array, $item->title);
    }
    }
    }
    ?>
  • Yes it did! Thank you so so much!