FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Creating your own pages in SMF and phpBB

 


grief
say you want to create a simple page in your forum with some text(or more) in it. Here's how you do that:

In SMF:

Go to your Sources directory, and create there a page called however you want, I'll call it myPage.php for this tutorial. Open up the page you just created and create a function inside it. I'll call mine myFunction() but yours could be anything you want. Here's the code:

Code:


<?

function myFunction()
{
if (!defined('SMF'))
{
       die('Hacking attempt...');
}
   global $context, $settings, $options, $scripturl, $modSettings, $txt;
   $context['page_title'] = 'Custom Title';     
  loadTemplate('myTemplate');
       
}

?>



of course, replace myFunction with the name of your function, and Custom Title with the title you want the page to have. At the end I wrote loadTemplate('myTemplate') so we'll have to go create this template.

Go to the Themes directory, then to the default directory, and create there a new file called myTemplate.template.php. myTemplate should be replaced with the template you gave to the loadTemplate. Here is how it should look:

Code:
<?

function template_main()
{
echo"my text";
}

?>


The function name here is not subject to change, but feel free to change "my text" and maybe put some php coding there as well.

Now lastly, go to index.php, and at the end, where you should see this line:
Quote:
// Here's the monstrous $_REQUEST['action'] array - $_REQUEST
and beneath it the monstrous list.

Decide on a name for your action, I'll call it myAct. Then look for where to put it alphabetically - myAct should come after movetopic2 and before notify. The code should look like this:

Code:
'myAct' => array('myPage.php', 'myFunction'),


Where myAct is the name of your action, myPage.php the adress of the page you created earlier, and myFunction the name of the function you created. Now save and you're all done.

Go to index.php?action=myAct (replace myAct with the name of your action) and you should see a page with the title and text you created.

I'm getting tired now, I'll post the same for phpBB tommorow.
grief
In phpBB:

Create a new page under the root directory of your forum. I willl call mine myPage.php.

The code should look like this:

Code:
<?php

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.' . $phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

$page_title = "Custom Title";

//
// Start page output
//
include($phpbb_root_path . 'includes/page_header.' . $phpEx);

      $template->set_filenames(array(
         'body' => 'myTemplate.tpl')
   );

include($phpbb_root_path . 'includes/page_tail.' . $phpEx);

?>


Replace the custom title with whatever you want the page's title to be.

You don't have to have a template file, if you want to have the page content on the php file itself, you can just replace

Quote:
$template->set_filenames(array(
'body' => 'myTemplate.tpl')
);
from the above code with echo"text"; or whatever you wish your content to be.

Now, if you do want to include a template. I named mine myTemplate, if you want yours to have a different name change myTemplate.tpl in the above code to something else(keep the .tpl extension, though).

Now you'll have to create that file. Go to the templates directory, and in each of the templates you're using, create a file called myTemplate.tpl, and in it, you can put basically whatever you want.
Reply to topic    Frihost Forum Index -> Miscellaneous -> Tutorials

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.