- This topic is empty.
-
AuthorPosts
-
April 15, 2009 at 9:42 pm #24609PattyRMember
So I added 2 rss feeds to one of my customers sites http://www.debbiedaanen.com and I managed to get everything modified to my liking except for one thing.
Limiting the length (or number of characters) that display for my content.
I was able to limit the number of characters for the title, and then placed a hellip at the end to signify the text was being cut off, but I can’t get it do the same for the content.
Here is my code
Code:Latest News
set_feed_url($url);
$feed->init();
$feed->strip_htmltags(array(‘img’,’embed’,’strong’,’html’,’onclick’,’onmouseover’,’onmouseout’,’center’));// default starting item
$start = 0;// default number of items to display. 0 = all
$length = 1;// if single item, set start to item number and length to 1
if(isset($_GET[‘item’]))
{
$start = $_GET[‘item’];
$length = 1;
}// set item link to script uri
$link = $_SERVER[‘REQUEST_URI’];// loop through items
foreach($feed->get_items($start,$length) as $key=>$item)
{// set query string to item number
$queryString = ‘?item=’ . $key;// if we’re displaying a single item, set item link to itself and set query string to nothing
if(isset($_GET[‘item’]))
{
$link = $item->get_link();
$queryString = ”;
}// display item title and date
echo ‘‘ . substr($item->get_title(), 0, 35) . ‘…‘;
echo ‘‘.$item->get_date(‘M j, Y’). ‘‘;// if single item, display content
if(isset($_GET[‘item’]))
{
echo ‘ ‘.$item->get_content().’
‘;
}
echo ‘
‘;echo $item->get_description();
}?>
Wall of Fame
set_feed_url($url);
$feed->init();
$feed->strip_htmltags(array(‘img’,’embed’,’strong’,’html’,’onclick’,’onmouseover’,’onmouseout’,’center’));// default starting item
$start = 0;// default number of items to display. 0 = all
$length = 1;// if single item, set start to item number and length to 1
if(isset($_GET[‘item’]))
{
$start = $_GET[‘item’];
$length = 1;
}// set item link to script uri
$link = $_SERVER[‘REQUEST_URI’];// loop through items
foreach($feed->get_items($start,$length) as $key=>$item)
{// set query string to item number
$queryString = ‘?item=’ . $key;// if we’re displaying a single item, set item link to itself and set query string to nothing
if(isset($_GET[‘item’]))
{
$link = $item->get_link();
$queryString = ”;
}// display item title and date
echo ‘‘ . substr($item->get_title(), 0, 35) . ‘…‘;
echo ‘‘.$item->get_date(‘M j, Y’). ‘‘;// if single item, display content
if(isset($_GET[‘item’]))
{
echo ‘ ‘.$item->get_content().’
‘;
}
echo ‘
‘;echo $item->get_description();}
?>
When I try to apply the same logic I used for my title to the content it makes my content disappear. So my current solution was just placing it in a div with overflow:hidden on the stylesheet, but being the php noob that I am… I would love to know why applying the same logic from the title to the content didnt work, and how I could make it work.
April 15, 2009 at 10:00 pm #56361PattyRMemberOk so I am still working on things as I posted this, and I somewhat fixed my problem. I did manage to limit my content characters, but now I need to fix it so that it doesn’t cut off words.
… If I manage to get it working I will post the code for others.
April 16, 2009 at 4:42 pm #56444Chris CoyierKeymasterYou should look into using PHP to truncate the string by words:
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.