spindrift Posted May 29, 2006 Share Posted May 29, 2006 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 Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 29, 2006 Share Posted May 29, 2006 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). Quote Link to comment Share on other sites More sharing options...
spindrift Posted May 29, 2006 Author Share Posted May 29, 2006 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 Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 29, 2006 Share Posted May 29, 2006 '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] Quote Link to comment Share on other sites More sharing options...
spindrift Posted May 29, 2006 Author Share Posted May 29, 2006 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.