|
01-02-2004, 11:40 AM | #1 |
Green Mole
Join Date: Dec 2003
Location: Texas
Posts: 7
|
PHP includes in templates
I have read through the forums, but still need help using PHP includes in the templates. Can someone please give detailed instructions on how to do this with some examples.
Maybe, somehow show how to include a header include and a footer include in the template file. I would love to use this excellent app... just need a little help to do it. |
01-02-2004, 08:18 PM | #2 |
Head Mole
Join Date: May 2003
Posts: 2,539
|
Hi. Say you want to include header.html and footer.html in a template.
First add the following function to the top of the search_function.php file: PHP Code:
PHP Code:
PHP Code:
Code:
<phpdig:my_page_header/> <phpdig:my_page_footer/>
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension. |
01-05-2004, 05:12 AM | #3 |
Green Mole
Join Date: Dec 2003
Location: Texas
Posts: 7
|
Wow, thanks for the in-depth reply. Exactly the response I was looking for. I think this will help a lot of people out including myself.
|
01-05-2004, 02:03 PM | #4 |
Green Mole
Join Date: Dec 2003
Location: Texas
Posts: 7
|
By the way, it worked like a charm. Thanks again.
|
04-01-2004, 06:52 PM | #5 |
Green Mole
Join Date: Mar 2004
Posts: 1
|
RE: PHP includes in templates
This is brilliant! Any way to modify this so that it can include AND parse any PHP in the include?
|
04-01-2004, 07:01 PM | #6 |
Head Mole
Join Date: May 2003
Posts: 2,539
|
Hi. Using the same method as above, you could include header.php, sidebar.php, and footer.php in a template, or you could also make your own custom PHP search page as follows.
In the search.php file do the following: PHP Code:
PHP Code:
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension. |
06-03-2004, 12:33 PM | #7 |
Green Mole
Join Date: Jun 2004
Posts: 3
|
Charter:
I followed your code above, modifying search_function.php and the template. I included a header and footer file. My scripts search_function.php Code:
I added to the top: function get_my_includes($filename) { if (file_exists($filename)) { $buffer = ""; $handle = fopen($filename, "r"); while (!feof($handle)) { $buffer .= fgets($handle, 4096); } fclose ($handle); return $buffer; } } Code:
$my_page_header = get_my_includes("./includes/header_aux.inc.php"); $my_page_footer = get_my_includes("./includes/footer_aux.inc.php"); if ($template == 'array' || is_file($template)) { $phpdig_version = PHPDIG_VERSION; $t_mstrings = compact('my_page_header','my_page_footer','powered_by_link','title_message','phpdig_version','result_message','nav_bar','ignore_message','ignore_commess','pages_bar','previous_link','next_link','templates_links'); $t_fstrings = phpdigMakeForm($query_string,$option,$limite,SEARCH_PAGE,$site,$path,'template',$template); if ($template == 'array') { return array_merge($t_mstrings,$t_fstrings,array('results'=>$table_results)); } else { $t_strings = array_merge($t_mstrings,$t_fstrings); phpdigParseTemplate($template,$t_strings,$table_results); } } Code:
<phpdig:my_page_header/> <phpdig:my_page_footer/> Cheers, JC |
06-03-2004, 05:54 PM | #8 | |
Purple Mole
Join Date: Jan 2004
Posts: 694
|
Quote:
<edit> BTW, I forgot to welcome you to the forum. Glad you could join us! </edit> |
|
06-04-2004, 04:50 AM | #9 |
Head Mole
Join Date: May 2003
Posts: 2,539
|
Hi. To parse PHP files, remove the get_my_includes function, as that reads but does not parse PHP files, and then replace:
PHP Code:
PHP Code:
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension. |
06-04-2004, 07:39 AM | #10 |
Green Mole
Join Date: Jun 2004
Posts: 3
|
Ok, Pat and Charter, I have tried both of your code examples. Thanks for the advice but I am still not having success... I decided to go with Charter's example for simplicity. I removed the get_my_includes function and changed the other code in search_function.php to
Code:
$my_header_file = include("./includes/header_search.inc.php"); $my_footer_file = include("./includes/footer_search.inc.php"); if ($template == 'array' || is_file($template)) { $phpdig_version = PHPDIG_VERSION; $t_mstrings = compact('my_header_file','my_footer_file','powered_by_link','title_message','phpdig_version','result_message','nav_bar','ignore_message','ignore_commess','pages_bar','previous_link','next_link','templates_links'); Code:
<phpdig:my_header_file/> normal phpdig code here <phpdig:my_footer_file/> Any other ideas on how I can get it to print a header then the phpdig content then the footer, in that order? Cheers, JC |
06-04-2004, 07:45 AM | #11 |
Head Mole
Join Date: May 2003
Posts: 2,539
|
Hi. Try taking a look at the HTML source from your page and then in the template just move <phpdig:my_header_file/> and <phpdig:my_footer_file/> so that the order is correct.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension. |
06-04-2004, 08:16 AM | #12 |
Green Mole
Join Date: Jun 2004
Posts: 3
|
Charter, thanks. There appeared to be no way to reorder the way they are listed to provide the desired result, given the order is
Code:
<phpdig:my_header_file/> normal phpdig code here <phpdig:my_footer_file/> I'm on a time limit so I gave up and hardwired the HTML into the template and got the result I 'wanted'. Thanks for your help. |
08-12-2004, 09:32 AM | #13 |
Green Mole
Join Date: Aug 2004
Posts: 1
|
I was having same problem as jclabaugh - order of template header and footer.
Found that this ordering is not adjusted in the HTML template file, it must be adjusted via the order of elements appearing in /libs/search_function.php Code should read something like this to place footer below PHPDig search results: PHP Code:
|
08-12-2004, 05:17 PM | #14 |
Purple Mole
Join Date: Jan 2004
Posts: 694
|
Welcome to the forum, subscript.
Your method of including a custom header/footer is certainly a pretty simple way of doing it. Thanks for sharing. It's nice to have someone post one more way of doing it. |
12-03-2004, 10:02 PM | #15 |
Head Mole
Join Date: May 2003
Posts: 2,539
|
Also, from php.net:
return.php PHP Code:
PHP Code:
PHP Code:
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension. |
Thread Tools | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
php includes template info | 5wayshost | Coding & Tutorials | 0 | 12-31-2006 09:59 PM |
Themes and PHP Includes | Arctic | Troubleshooting | 3 | 05-07-2005 08:21 PM |
Using PHP include in templates | sid | How-to Forum | 3 | 11-23-2003 06:06 AM |
PHP includes in Template? | jirving | How-to Forum | 1 | 09-29-2003 02:37 PM |
Templates - cannot get index.php to display different one | jirving | How-to Forum | 9 | 09-29-2003 05:57 AM |