MyBB Community Forums

Full Version: Custom PHP pages + MyBB templates. No Plugin, No Problem. Super Easy!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I found This Tutorial by Marcus Avrelius over at "Let's Forum", but had to make some slight modifications to get it to work correctly.  Because there is quite a bit of interest in this kind of thing, I thought I would share how I made it work for me.


Creating Custom PHP Pages that use MyBB Templates: No Plugin, No Problem!


    1.  Make sure your forum settings are configured correctly.
  • Admin CP --> Configuration --> Site Details
  • My configuration looks like this:
Board URL:      http://localhost/MyForum
Homepage URL:   http://localhost/
Cookie Domain:  localhost
Cookie Path:    /
Cookie Prefix:  

Your site structure may be different, but I am sharing what settings I am using so if you have any issues, you have a reference as to what configurations are working for me.  [Note:  I am working locally which is why I am using "localhost" - your settings should be your_domain.com or whatever].


    2.  Create your MyBB template.
  • Admin CP --> Templates & Style --> Templates --> Global Templates --> Add Template
  • Name your template whatever you like.
  • "Template Set" should be "Global Templates"
  •  Create your template as normal.
     
<html>
<head>
<title>Your Site</title>
{$headerinclude}
</head>
<body>
{$header}
   Use whatever MyBB Markup you want.
{$footer}
</body>
</html>



    3.  Create a new PHP file and copy/paste the following lines of code:
<?php
define("IN_MYBB",1);
include("global.php");
eval("\$page .= \"".$templates->get("your-template-name-goes-here")."\";");
output_page($page);    
?>

  • Replace "your-template-name-goes-here" with whatever you named the MyBB template you created in step 2.
  • You may name your new page whatever you like & save it as a php file.
    4.  Move your new page into your MyBB root directory.
  • This is the same directory where "global.php" is located.
  • Example:  path/to/yourMyBBforum/YOUR_NEW_PAGE.php
  • Now, open your page in your browser and enjoy the view Smile


If you are like me, you may want your page located in the main directory of your site.  If that is the case, (1) just update the code in your php file to the following:

<?php
chdir("MyForum/"); // YOUR MyBB file path
define("IN_MYBB", 1);
require("./global.php");
chdir("../");
eval("\$page .= \"".$templates->get("your-template-name-goes-here")."\";");
output_page($page);
?>

(2) EDIT "MyForum" & "your-template-name-goes-here" appropriately, and (3) move your php page up a directory.  In my case, my custom page is located at "localhost/mypage.php", but you may modify this to point to whatever directory you like.  Remember, you only have to modify the php file, not the template in the Admin CP.

Happy Customizing!
=)
<?php 

define('IN_MYBB', 1); require "./global.php";

add_breadcrumb("Title here", "somename.php"); 

eval("\$html = \"".$templates->get("template_name")."\";"); 

output_page($html);

?>

Works too.