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.
$feed = new SimplePie(); $feed->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 '<a href=\"http://www.debbiedaanen.com/blog/blog.html\">' . substr($item->get_title(), 0, 35) . '...</a>'; echo '<span>'.$item->get_date('M j, Y'). '</span>';
// if single item, display content if(isset($_GET['item'])) { echo ' <span>'.$item->get_content().'</span><br>'; } echo '<br>';echo $item->get_description(); }
$feed = new SimplePie(); $feed->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 '<a href=\"http://www.debbiedaanen.com/blog/wall_of_fame.html\">' . substr($item->get_title(), 0, 35) . '...</a>'; echo '<span>'.$item->get_date('M j, Y'). '</span>';
// if single item, display content if(isset($_GET['item'])) { echo ' <span>'.$item->get_content().'</span><br>'; } echo '<br>';echo $item->get_description();
}
?> </div>
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.
Ok 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.
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
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.
... If I manage to get it working I will post the code for others.
http://snippets.dzone.com/posts/show/412