PDA

View Full Version : Simplepie blogfeed in template



ChrisGooding
02-15-10, 02:33 PM
Hi Guys,

Struggling here :(

We use the simplepie feed to pull our blog articles through from our blog. This works fine, however for some reason I cannot get it working on our whmcs pages, as whenever the code is on the page, it simply breaks, producing a white screen.

The code I use on our site is....

<?php
// Make sure SimplePie is included. You may need to change this to match the location of simplepie.inc.
require_once('my/include/path/simplepie.inc');

// Initialize new feed
$feedblog = new SimplePie('https://www.xtrgameservers.com/blog/feed/');
$feedblog->handle_content_type();
$i=0;
foreach ($feedblog->get_items() as $item) {
$i++;
if($i <= 4){
echo '<span class="title"><a href="'.$item->get_permalink().'" title="'.$item->get_title().'">';
echo $item->get_title().'</a></span>';

$post = $item->get_description();

$post = html_entity_decode(substr($post, 0, 65));
$pos = strrpos($post, " ");
if ($pos>0) {
$post = substr($post, 0, $pos);
}

echo '<p>'. $post .'... </p>';
}
}
?>

I have tried this a number of ways on the template, including all of the below

Substituting <php blah blah blah ?>

for

{php} blah blah blah {/php}

I have trie dpulling it through using both...
{php} include ('path/to/file/with/code/insideit.php'){/php}

and

{include_php file="path/to/file/with/code/insideit.php"}

And not to mention every god damn path variant known to man, just to rule out issues with file location.

Any ideas....... Im starting to think its an issue with the code itself that is used to pull the feeds.

Any help greatly appreciated.

m00
02-15-10, 02:53 PM
It should work when you use it this way:

{php}
// Make sure SimplePie is included. You may need to change this to match the location of simplepie.inc.
require_once('my/include/path/simplepie.inc');

// Initialize new feed
$feedblog = new SimplePie('https://www.xtrgameservers.com/blog/feed/');
$feedblog->handle_content_type();
$i=0;
foreach ($feedblog->get_items() as $item) {
$i++;
if($i <= 4){
echo '<span class="title"><a href="'.$item->get_permalink().'" title="'.$item->get_title().'">';
echo $item->get_title().'</a></span>';

$post = $item->get_description();

$post = html_entity_decode(substr($post, 0, 65));
$pos = strrpos($post, " ");
if ($pos>0) {
$post = substr($post, 0, $pos);
}

echo '<p>'. $post .'... </p>';
}
}
{/php}


If you still get a white page, can you place $display_errors = true; in your configuration.php and post which error you're getting on the page?

ChrisGooding
02-15-10, 03:14 PM
Hi Thanks, I had tried that, but didn't post the error..... should have done really.

The error is:-



Warning: require_once(templates/xtrgameservers-3/scripts/simplepie.inc) [function.require-once]: failed to open stream: No such file or directory in /var/www/testwhmcs/templates_c/%%95^95F^95F4DC4A%%footer.tpl.php on line 46

Fatal error: require_once() [function.require]: Failed opening required 'templates/xtrgameservers-3/scripts/simplepie.inc' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/testwhmcs/templates_c/%%95^95F^95F4DC4A%%footer.tpl.php on line 46


Looks like it was being held up by the template cache, but I have cleared them and no difference.

m00
02-15-10, 03:18 PM
Hi Thanks, I had tried that, but didn't post the error..... should have done really.

The error is:-


Warning: require_once(templates/{$template}/scripts/simplepie.inc) [function.require-once]: failed to open stream: No such file or directory in /var/www/testwhmcs/templates_c/%%95^95F^95F4DC4A%%footer.tpl.php on line 46

Fatal error: require_once() [function.require]: Failed opening required 'templates/{$template}/scripts/simplepie.inc' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/testwhmcs/templates_c/%%95^95F^95F4DC4A%%footer.tpl.php on line 46

Looks like it was being held up by the template cache, but I have cleared them and no difference.

Are you trying to use {$template} inside your require_once()? That isn't going to work. Just replace it with your template name, or try this:

require_once("templates/".$this->_tpl_vars['template']."/scripts/simplepie.inc");

ChrisGooding
02-15-10, 03:26 PM
Yep, sussed it that was causing the issue :lol:

The page doesn't break now....... feed doesn't pull through, but at least the page isn't broke :)

Will update here once I know what the issue is should anyone else come across this.