Jump to content

Simplepie blogfeed in template


ChrisGooding

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Edited by ChrisGooding
Link to comment
Share on other sites

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");

Edited by m00
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated