MyBB Community Forums

Full Version: PHP Insertion Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hello,
I would like to display some news from a third-party script on the homepage of my forum (index.php). The code that I have to use is something like:
include("path/to/show_news.php");

How would I be able to use that in my index page? When I add it to the index.php file, it does not display where I want it to on the page (of course).

What I would like to do is have something like "$news" added to a template, and the news would appear on the index. Could anyone help me with this? Thanks in advance for any replies!
kodaks Wrote:Hello,
I would like to display some news from a third-party script on the homepage of my forum (index.php). The code that I have to use is something like:
include("path/to/show_news.php");

How would I be able to use that in my index page? When I add it to the index.php file, it does not display where I want it to on the page (of course).

What I would like to do is have something like "$news" added to a template, and the news would appear on the index. Could anyone help me with this? Thanks in advance for any replies!

If your show_news.php script uses echo or print to output the news content, try using output buffering to capture all the stuff that would be outputed, into a variable. Then you will be able to use that variable in the index template.

ob_start();
include("path/to/show_news.php");
$news = ob_get_clean();



If your show_news.php script already outputs all the news into a variable, then just use that variable in the index template.

If you attach the show_news.php script, it would be easier to help you.
Thanks for the reply, I have attached it. It is a CuteNews script if that is any help.
Did you try what I posted?
Yes, the php code you gave me worked excellently:
ob_start();
include("path/to/show_news.php");
$news = ob_get_clean();

Thank you very much!
Hi,
How would I apply it to the following php page code?
<?php
$templatelist = "newsportal";
require "./global.php";
eval("\$newsportal = \"".$templates->get("newsportal")."\";");
outputpage($newsportal);
?>
I tried adding it before ?>, but it did not show up.

Thanks!
try this
ob_start();
$templatelist = "newsportal";
require "./global.php";
eval("$newsportal = "".$templates->get("newsportal")."";");
outputpage($newsportal);
ob_get_clean();
Thanks for your reply, but I don't think that does the trick. I am trying to add the following code to my current file, so the two work hand in hand.

Here is the code I want to add:
ob_start();
include("path/to/show_news.php");
$news = ob_get_clean();

This is the file I want to add it to:
<?php
$templatelist = "newsportal";
require "./global.php";
eval("\$newsportal = \"".$templates->get("newsportal")."\";");
outputpage($newsportal);
?>
<?php
ob_start();
include("path/to/show_news.php");
$news = ob_get_clean();

$templatelist = "newsportal";
require "./global.php";
eval("\$newsportal = \"".$templates->get("newsportal")."\";");
outputpage($newsportal);
?>
Thanks!
Pages: 1 2 3