Jump to content

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
Link to comment
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).
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

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.