Jump to content

Archived

This topic is now archived and is closed to further replies.

spindrift

How can I ask my php include to search 2 folders for content?

Recommended Posts

Hi guys,

I'm using the below code to call content into my websites' layout:

[code]<?php @ require_once ("$pagename.php"); ?>[/code]

At the moment, I believe it will only search for files in the same folder as my main template which is fine.

The thing is though, is that I want to put all the news files in a folder called 'news'. Is there a way that this code can be edited so it can not only search for and include files in the same folder but also news/ ?

Thank you very much and I hope to hear from you.

All the best,

Mark

Share this post


Link to post
Share on other sites
You can check whether a file exists using this -[a href=\"http://ca3.php.net/manual/en/function.file-exists.php\" target=\"_blank\"]php.net/manual/en/function.file-exists.php[/a]. That would let you test for the existence of a file that might be in either location, and only include it when you find it (and from where).

Share this post


Link to post
Share on other sites
hi andyb,

many thanks for the reply.

ill be honest and say i'm new to php and don't really understand all the code in the manual - let alone how to edit it for my needs!

is there a simpler way where the script i posted can search in the news folder? if so, could i be a pain and ask if you would mind telling me the code i need please?

thank you very much once again and i hope to hear from you.

mark

Share this post


Link to post
Share on other sites
'Search' isn't what you want then? All you need is to include it from a different folder if it exists.
[code]<?php
$the_page = "news/". $pagename. ".php";
@include($the_page); ?>[/code]

Share this post


Link to post
Share on other sites
hi andy,

thanks for that and for getting back to me...

i put the code in my template file next to [code]<?php @ require_once ("$pagename.php"); ?>[/code] but it didn't work.

basically what i am after is <?php @ require_once ("$pagename.php" or news/$pagename.php); ?> but i wouldn't know how to write it properly. do you know how it should be written properly?

thank you very much for everything.

all the best,

mark

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.