Feb 27, 2016 05:26 PM
(This post was last modified: Oct 5, 2016 11:48 PM by VirtualFrost.)
Creating a Custom Page in MyBB
Introduction
Creating a custom page on your MyBB forum is a really common question around new developers around MyBB forums. Today I will be going through for you how exactly to get your own custom page, that still fits your layout of your forum. This page could be used for anything that doesn't need a forum layout such as an upgrade page, stats, or any other information that doesn't fit into a regular forum format.
Step One
Go to the root directory of your MyBB files, this is where you'll be placing your MyBB page, we'll get into linking it up to your forum in a moment. Your forum root directory should look something similar to this:
![[Image: RgUwFZJ.png]](https://i.imgur.com/RgUwFZJ.png)
We'll be making an upgrade page as an example, so your users have a place to get information about upgrading. Create a new file called upgrade.php (MUST be a PHP file). Open up your new PHP file you created and put the following code inside of it:
PHP Code
<?php
define('IN_MYBB', 1); require "./global.php";
add_breadcrumb("Upgrade", "upgrade.php");
eval("\$html = \"".$templates->get("upgrade")."\";");
output_page($html);
?>
Step Two
Now head to your Admin Control Panel, looking at the default theme it should be at the top of your theme like so
![[Image: HWCmalJ.png]](https://i.imgur.com/HWCmalJ.png)
If you cannot find your AdminCP(ACP), put "/admin/index.php" at the end of your home page link(https://yourwebsite.com/admin/index.php OR https://yourwebsite.com/<foldername>/admin/index.php if your forum isn't sitting in your root directory) and you should arrive at the login. Your login is the same information as your username and password to log into your forum. Once inside, head to the "Templates & Styles" tab, go into your theme template and click "Add Template".
![[Image: gmPadwy.png]](https://i.imgur.com/gmPadwy.png)
![[Image: 8iULSe9.png]](https://i.imgur.com/8iULSe9.png)
Name the template the same as your file you created and put the following code into the template box:
Code <html>
<head>
<title>Upgrade</title>
{$headerinclude}
</head>
<body>
{$header}
<table border="0" cellspacing="1" cellpadding="4" class="tborder">
<tr>
<td class="thead"><span class="smalltext"><strong>Upgrade</strong></span></td>
</tr>
<tr>
<td class="trow1">
Add here your custom messages.
</td></tr></table>
{$footer}
</body>
</html>
Once everything is complete, click "Save and Continue Editing" if you wish to save but stay on that page, or click "Save and Return to Listing" to exit the editing stage. That's it! Now you can see your page by heading to https://yourwebsite.com/upgrade.php, and you should see your brand new page.
![[Image: Al4XmVY.png]](https://i.imgur.com/Al4XmVY.png)
Any customizations are done with simple HTML and CSS; you can even get a little more advanced with adding JavaScript to your pages. Imagine it as a blank canvas and you're ready to create whatever you need on your page.
Please Remember
Anything that you have already added to your themes may not show up here if they haven't been put inside your header or footer. If you'd like your own custom things to show up here, either move it so it goes into the footer or header, or code it into this page.
![[Image: LEGENDS_2_0_DELIMETER.png]](https://s9.postimg.org/jzubyp2v3/LEGENDS_2_0_DELIMETER.png)
Credit to this thread, without it I wouldn't have gotten the help I needed to learn this as well.
Well done. Just a few things though. With the root directory, you've made it look like all you've done is downloaded the MyBB pack and opened it on your computer. You should actually considering showing an obvious root directory such as a cPanel's public_html or htdocs. Common sense isn't so common so many people might actually think the root directory is on their desktop somewhere. Second thing is when eval is called, you should be declaring a variable shortly after. In this case, it's the template name.
The " if your forum isn't sitting in your root directory" looks like a half-finished sentence. Perhaps add on that they can find their ACP path in the /inc/config.php file.
All in all, a nice tutorial.
(Feb 27, 2016 07:29 PM)Wires Wrote: Well done. Just a few things though. With the root directory, you've made it look like all you've done is downloaded the MyBB pack and opened it on your computer. You should actually considering showing an obvious root directory such as a cPanel's public_html or htdocs. Common sense isn't so common so many people might actually think the root directory is on their desktop somewhere. Second thing is when eval is called, you should be declaring a variable shortly after. In this case, it's the template name.
The " if your forum isn't sitting in your root directory" looks like a half-finished sentence. Perhaps add on that they can find their ACP path in the /inc/config.php file.
All in all, a nice tutorial. The whole 'just downloaded' thing, I thought would be easiest to show as this would basically be all the assets you'd see in the directory, hoping it would be easier to show this way, however I can do that!
With calling the variable shortly after, what is the purpose of this? Does it change anything at all? Never knew about this.
And I'll fix that sentence up now, I understand where you're coming from. Thanks for the feedback! Much appreciated 🤝
Feb 27, 2016 07:49 PM
(This post was last modified: Feb 27, 2016 07:50 PM by Wires.)
When I say declare the variable, I mean the bit where you say "Open up your new PHP file you created and put the following code inside of it:" and "Name the template the same as your file you created and put the following code into the template box:"
The first sentence you forgot to mention that you actually need to edit the content inside of it, and not just put the following code inside the PHP file. The second sentence is actually wrong. If you make a page called upgrade.php (with the code you said to put inside)and place it within the root of your MyBB directory, the page will actually come up blank regardless of what you name the template. You actually need to edit the following line (which you may already know but haven't mentioned):
Code eval("\$html = \"".$templates->get("template_name")."\";");
The "template_name" needs to correspond with the actual template name which is why your second sentence is wrong. The template name and the file name can still be the same and not work.
Feb 27, 2016 11:17 PM
(This post was last modified: Feb 27, 2016 11:22 PM by VirtualFrost.)
(Feb 27, 2016 07:49 PM)Wires Wrote: When I say declare the variable, I mean the bit where you say "Open up your new PHP file you created and put the following code inside of it:" and "Name the template the same as your file you created and put the following code into the template box:"
The first sentence you forgot to mention that you actually need to edit the content inside of it, and not just put the following code inside the PHP file. The second sentence is actually wrong. If you make a page called upgrade.php (with the code you said to put inside)and place it within the root of your MyBB directory, the page will actually come up blank regardless of what you name the template. You actually need to edit the following line (which you may already know but haven't mentioned):
Code eval("\$html = \"".$templates->get("template_name")."\";");
The "template_name" needs to correspond with the actual template name which is why your second sentence is wrong. The template name and the file name can still be the same and not work. OH yes, I'll make all that more clear and explain you need to edit it to whatever you need it to be called, also missed editing that 'template_name' whoops, thanks again!
Nice tutorial, was looking around for this. I added the link in my header I just don't have a page yet anyways it would be cool if you showed the process of using filezilla aka ftp for it
(Mar 5, 2016 06:44 PM)Natalie Dormerr Wrote: Nice tutorial, was looking around for this. I added the link in my header I just don't have a page yet anyways it would be cool if you showed the process of using filezilla aka ftp for it
I'll try get that in within the next 48 hours. Thanks for the suggestion 🤝
thank you for this guide I will be using this soon!
Thanks for your tutorial, it's a nice contribution to this section
|