PHP Insertion Question
#1
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!
#2
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.
Dennis Tsang
Former MyBB Team Member
Web: http://dennistt.net
#3
Thanks for the reply, I have attached it. It is a CuteNews script if that is any help.


Attached Files
.php   show_news.php (Size: 4.18 KB / Downloads: 310)
#4
Did you try what I posted?
Dennis Tsang
Former MyBB Team Member
Web: http://dennistt.net
#5
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!
#6
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!
#7
try this
ob_start();
$templatelist = "newsportal";
require "./global.php";
eval("$newsportal = "".$templates->get("newsportal")."";");
outputpage($newsportal);
ob_get_clean();
[Need Smilies? Get Me Smileys!
#8
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);
?>
#9
<?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);
?>
Dennis Tsang
Former MyBB Team Member
Web: http://dennistt.net
#10
Thanks!


Forum Jump:


Users browsing this thread: 1 Guest(s)