====== Descriptions in RSS aggregator ====== The [[:rss#rss_aggregation]] is a nice feature but I like to have the beginning of the articles from one feed on the same page. For example: * [[http://go.theregister.com/feed/http://www.theregister.co.uk/2005/12/02/bofh_2005_episode_33/|BOFH: the PFY goes AWOL]] Wasn't he just in the tape safe? Episode 33 It's a quiet afternoon in Mission Control when I'm woken from my slumber by a dull banging noise coming... * [[http://go.theregister.com/feed/http://www.theregister.co.uk/2005/11/25/bofh_2005_episode_32/|BOFH: Woah there, Crash Gordon]] Percussive maintenance Episode 32 "WOAH THERE, Crash Gordon!" the PFY shouts as our engineer prepares to put our system back together "How's about ... Very few modifications are needed to have this behavior in DokuWiki ===== inc/parser/xhtml.php ===== The whole description maybe sometimes too much. It will then be truncated. An example function found on [[http://www.php.net/substr_replace|php.net]] does the trick, even adding ellipsis ! It is added as a method of ''Doku_Renderer_xhtml'': /** * Truncate a string to the specified number of characters, adding ellipsis * * @author http://www.php.net/substr_replace */ function truncate($substring, $max = 50, $rep = '...') { if(strlen($substring) < 1){ $string = $rep; }else{ $string = $substring; } $leave = $max - strlen ($rep); if(strlen($string) > $max){ return substr_replace($string, $rep, $leave); }else{ return $string; } } We can then use it to display a truncated description for every article: function rss ($url){ (...) $i=0; foreach ($rss->items as $item ) { $this->doc .= '
  • '; $this->externallink($item['link'],$item['title']); $this->doc .= '
    ' . $this->truncate(strip_tags($item['description']),150); $this->doc .= '
  • '; if($i++>=4) break; } (...) }
    Note the ''$i'' variable which ensures that no more than 5 headlines are displayed. --- //[[shtrom-doku@ssji.net|Olivier Mehani]] 2005-12-03 01:00//