We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38705
    • 101 Posts
    Hi,
    Who can help me with this problem?

    I have a RSS Feed from which i want to display items on my website. I use the nice spieFeed 1.5 addon by Goldsky. The plugin will parse the items with a template called FeedItems.

    <ul>
    	[[!spieFeed? 
    		&setFeedUrl=`urltothefeed /feed.rss` 
    		&tpl=`FeedItems` 
    		&setItemLimit=`2` 
    		&enableCache=`0`
    	]]
    </ul>
    


    The template FeedItems is as follows:
    <li>
    	<a href="[[+link]]" class="thumb">
    		<img src="/partners/number_1.jpg" 
    		width="72" height="48">
    	</a>
    	<em> door [[+authorName]] &raqou; [[+localDate:ago]]</em>
    	<h3><a href="[[+link]]">[[+title]]</a></h3>
    		<p>[[+content:strip:stripTags:ellipsis=`200`]]</p>
    			<div class="clear"></div>
    </li>
    


    So far so good. I get a nice output.

    Now i would like to randomize the image that shown with each FeedItem, so i wrote a little snippet: Number

    <?php
    $number = rand(1,9);
    return $number;
    

    which will output a random number between 1 to 9 on every call.

    So if i go back to my template FeedItems and edit the code to include my snippet uncached:

    <li>
    	<a href="[[+link]]" class="thumb">
    		<img src="/partners/number_[[!Number]].jpg" 
    		width="72" height="48">
    	</a>
    	<em> door [[+authorName]] &raqou; [[+localDate:ago]]</em>
    	<h3><a href="[[+link]]">[[+title]]</a></h3>
    		<p>[[+content:strip:stripTags:ellipsis=`200`]]</p>
    				<div class="clear"></div>
    </li>
    


    If i now call spieFeed to generate my list. I would think that on every < L I > created by the FeedItems template a random number would be inserted to display my random image.
    However, one number is generated and then parsed into all < L I > items.

    Can anyone tell met how to integrate my snippet into the template so it will work?
    What am I doing wrong?

    This question has been answered by mintnl. See the first response.

    [ed. note: mintnl last edited this post 14 years, 3 months ago.]
      Addict since 2012....
    • discuss.answer
      • 38705
      • 101 Posts
      I couldn't get the above idea to work but have managed to create another idea:
      Pictures in the content or A-Z 0-9 in a folder (/images/firstimage).
      Let a snippet determine if there is a image-tag present in the content of the feed. If so, use it. If not determine the first letter of the content is and use this letter as a picture.

      In my template:
      <h3>Feed items!</h3>
      		<div class="widget-container widget_recent_posts">
      			<ul>
      				[[!spieFeed? 
      					&setFeedUrl=`http ://complete.url/ to/feed.rss` 
      					&tpl=`FeedItems` 
      					&setItemLimit=`5` 
      					&enableCache=`0`
      				]]
      			</ul>
      		</div>
      


      Chunk: FeedItems
      <li>
          <a href="[[+link]]" class="thumb">
      	<img src="
      	[[+content:firstimage=`
      		[[+title:substring=`0,1`]]
      			`:phpthumbof=`w=72&h=48&zc=1&q=80`]]">
        </a>
      		<em> door [[+authorName]] » [[+localDate:ago]]</em>
      <h3><a href="[[+link]]">[[+title]]</a></h3>
      <p style='margin-top:-15px'>
      [[+content:replace=`< b r / >
      == `:strip:stripTags: ellipsis=`150`]]</p>
      					<div class="clear"></div>
      </li>
      


      Snippet: firstimage (used as output modifier)
      <?php
      if(preg_match('/^[a-zA-Z0-9]+$/',$options[0])){
      $firstletter = strtolower($options[0]);
      }else{
      $firstletter = "none";
      }
      
      $doc = new DOMDocument();
      @$doc->loadHTML($input);
      
      $tags = $doc->getElementsByTagName('img');
      
      foreach ($tags as $tag) {
             $output[] =  $tag->getAttribute('src');
      }
      if(strlen($output[0]) > 0){ $imgurl = $output[0]; }
      else {
      $imgurl = '/images/firstimage/'.$firstletter.'.png';
      }
      
      return $imgurl;
      ?>
      


      Snippet: substring
      <?php
      $options=explode(',',$options);
      return count($options)>1 ? 
      	substr($input,$options[0],$options[1]) : 
      	substr($input,$options[0]);
      ?>
      


      PS, remove the obvious extra spaces and line breaks....

      Maybe anyone can use it,hope it helps

      Cheers,
      Michiel [ed. note: mintnl last edited this post 14 years, 3 months ago.]
        Addict since 2012....