Practical.Add custom page

= Add a New Custom Page to phpBB =

Knowledge Base Add a New Custom Page to phpBB Article ID: 107 Written By: pentapenguin Written On: Thu Aug 21, 2008 10:38 pm Description: Need to add a new page to your web site that matches the look and feel of your forums? Then read this how-to article.

Hello

This tutorial will show you how to add a new customized page to phpBB. Why would you want to do this? Say for example, you want to make a new web page that looks just like your forum. This new page can contain anything you want from simple text like a list of rules to more complicated things like other PHP scripts, for example, calendars. Let's get started.

The aboutus.php file
When you are creating the aboutus.php page, make sure there are no blank lines and/or spaces before the  parts. Also ensure the file is encoded as UTF-8 without BOM. (The correct encoding can be achieved by using an appropriate text editor to create the file).

For this example, we'll create a simple page that tells a little about the site. Copy and paste the code below into your favourite text editor.

session_begin; $auth->acl($user->data); $user->setup;

page_header('Title Here');

$template->set_filenames(array( 'body' => 'yourpage_body.html', ));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx")); page_footer;

?>

Is that it? Not quite, so let me explain.

If you are creating a completely custom page, you probably won't need to do this, but if you need access to the phpBB language files, then change this line:

$user->setup;

to this:

$user->setup('base-name-of-language-file-here');

Replace base-name-of-language-file-here with the name of the language file you want without the .php extension. For example, if you need to load the viewtopic.php language file, then use this code:

$user->setup('viewtopic');

The first change you need to change is this line:

page_header('Title Here');

Just change Title Here to whatever you want displayed in the title bar of the browser. For our example, we'll change it to About Us.

The next thing you will need to change is this line: 'body' => 'yourpage_body.html',

Again, let me explain further why you need to change this. phpBB separates the logic of the page (all the PHP code) from the design (colours, images, backgrounds, etc.) and text (the HTML file). You will need to change yourpage_body.html to something more clear like aboutus_body.html -- and we're done editing this file. Save the file above in your text editor as aboutus.php (note: Microsoft Windows may try to add a .txt extension on the end so if that happens, save it as "aboutus.php" including the quote marks).

Bonus Tip
If you would like to restrict access to the page to logged in users only, then find this line

$user->setup;

and add this bit of code after that

if ($user->data['user_id'] == ANONYMOUS) {   login_box('', $user->lang['LOGIN']); }

Note: The above code of course allows access to search engine bots, because they are not "ANONYMOUS". If you want to restrict access to bots you need to check this too:

if ($user->data['is_bot']) {  redirect(append_sid("{$phpbb_root_path}index.$phpEx")); } in this case they are redirect to the index page as a loop.

The aboutus_body.html file
Next, we'll create the HTML file that contains the actual content of aboutus.php. Again, with your favourite text editor open, copy the following code:

Title Here

Content in here.

This is pretty easy to do. To change the name of the page which is displayed in big letters near the top, just change this line: Title Here

Replace Title Here with About Us.

And this is the section where you include all of your actual content:

Content in here.

You can add whatever HTML and CSS code and text in here you want. (If you don't know HTML or CSS, I'd recommend learning them. Both are easy to learn. The W3Schools site has excellent tutorials.) Here's a quick example with a little bit of text and a list of items:

We were founded this year to bring you the best forum on the Internet! We promise to do the following:  Provide new content provide a friendly atmosphere Provide an environment where you can have fun! 

Wrapping it up
If you followed the directions here are what the two files should look like now:

aboutus.php: session_begin; $auth->acl($user->data); $user->setup;

page_header('About Us');

$template->set_filenames(array( 'body' => 'aboutus_body.html', ));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx")); page_footer;

?>

aboutus_body.html:

About Us

We were founded this year to bring you the best forum on the Internet! We promise to do the following:  Provide new content provide a friendly atmosphere Provide an environment where you can have fun!</li> </ul>

Final steps
Now save the file you were just changing as aboutus_body.html and upload it to the styles/your style name here/template/ directory on your web server. Also upload the aboutus.php file to your web server in the main phpBB directory (the same place where you uploaded files like faq.php, viewforum.php, viewtopic.php, etc.).

Finally go to http://www.example.com/the-place-where-you-installed-phpbb/aboutus.php to see your brand new custom page!

Enjoy!