Page 1 of 1

Get a file and add it example: news.php?filename

Posted: Mon Aug 17, 2009 1:22 pm
by DM01
I've been messing with php for a few weeks now and haven't been able to find this answer.

Basically what I'm trying to do is make a news template for my site and add an article to it so I don't have to make a page for each article. I was thinking news.php?filename then whatever the file name do the include command on the page. Any help would be appreciated.

Re: Get a file and add it example: news.php?filename

Posted: Mon Aug 17, 2009 1:37 pm
by jackpf
Why not use a database?

Re: Get a file and add it example: news.php?filename

Posted: Tue Aug 18, 2009 2:25 pm
by DM01
Databases are out of my league at the moment. I'm just trying to save myself a ton of page edits if I need to add something to a template and my articles start reaching the 10-20 range.

Re: Get a file and add it example: news.php?filename

Posted: Tue Aug 18, 2009 2:32 pm
by jackpf
Well...you're probably setting yourself up for more work in the long run by not using a database....

But what are you having trouble with?

You could do this:

Code: Select all

//all your formatting
$tpl = basename($_GET['filename']);
$tpl = ((in_array($tpl, array('valid', 'template', 'files')) ? $tpl : 'default_template').'template_extension';
include $tpl;
//more formatting