Results 1 to 3 of 3

Thread: Limit Title Chars on RSS Display Box Script

  1. #1
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Limit Title Chars on RSS Display Box Script

    1) Script Title:
    RSS Display Boxes

    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamici...ybox/index.htm

    3) Describe problem:
    Is there a way to limit the amount of characters for the title? Script runs great but some of the feed titles are too long and I need to limit them.

    Thanks,

    Tony

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    OK, not a PHP expert here, but after doing a bit of digging around and experimenting, it appears obvious that the title is output by the outputbody.php file.

    If you were to replace it with this one:

    Code:
    <?
    //Function for ouputting the body of each RSS item displayed (inside loop)- DynamicDrive.com
    //For syntax pf bpdu, see: http://simplepie.org/docs/installation/from-scratch/ and http://simplepie.org/docs/reference/
    //Function by default defines 3 different body outputs (templates). Modify or add additional templates as desired
    
    function shortentitle($title, $len=10){
    if(strlen($title) > $len)
    echo substr($title, 0, $len - 6) . ' . . .';
    else
    echo $title;
    }
    
    function outputbody($item, $template=""){
    if ($template=="" || $template=="default"){ //DEFAULT TEMPLATE
    	?>
    	<DIV class="rsscontainer">
    	<div class="rsstitle"><a href="<?php echo $item->get_permalink(); ?>"><?php shortentitle($item->get_title()); ?></a></div>
    	<div class="rssdate"><?php echo $item->get_date('d M Y g:i a'); ?></div>
    	<div class="rssdescription"><?php echo $item->get_description(); ?></div>
    	</DIV>
    	<?
    } //end default template
    else if ($template=="titles"){ //"TITLES" TEMPLATE
    	?>
    	<DIV class="rsscontainer">
    	<div class="rsstitle"><a href="<?php echo $item->get_permalink(); ?>" target="_new"><?php shortentitle($item->get_title()); ?></a></div> 
    	<div>Category: <?php echo $item->get_category(); ?></div>
    	</DIV>
    	<?
    } //end titles template
    else if ($template=="titlesdates"){ //"TITLESDATES" TEMPLATE
    	?>
    	<DIV class="rsscontainer">
    	<span class="rsstitle"><a href="<?php echo $item->get_permalink(); ?>"><?php shortentitle($item->get_title()); ?></a></span> 
    	<span class="rssdate"><?php echo $item->get_date('m/d/y g:i a'); ?></span>
    	</DIV>
    	<?
    } //end titlesdates template
    else if ($template=="mytemplatename"){ //"mytemplatename" TEMPLATE
    	?>
    	//DEFINE ADDITIONAL CUSTOM TEMPLATE(s) USING SAME LOGIC STRUCTURE AS ABOVE
    	//For syntax of template body, see SimplePie docs: http://simplepie.org/docs/installation/from-scratch/ and http://simplepie.org/docs/reference/
    	<?
    }
    
    
    
    
    else
    die ("No template exists with such name!");
    } //Closing function bracket
    ?>
    You should be able to get what you want. Notice particularly the:

    Code:
    function shortentitle($title, $len=10){
    near the beginning. The red 10 determines the maximum length for the title. All titles longer than that will have their last 6 characters up to 10 replaced with:

    Code:
     . . .
    and the rest dropped. Obviously 10 characters are probably too short, so adjust that red number as desired. It will be the maximum length including the padding dots of any title. Any title shorter or equal to this number in length will appear in its entirety without the padding dots.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    progresst (10-11-2009)

  4. #3
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Many thanks!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •