ToolBox -

December 12th, 2011

Print this article

Add a comment!

 

Looking for a easy way to create pages in WHMCS? We can recommend the WHMCS Pages module by No Half Pixels. We’ve tested it with all templates and it works flawlessly.

Click Here To Purchase

 

Video Guide

Click the link below to view our in-depth video showing you how to create a page in WHMCS using this guide.

Click Here To Watch Our Video Guide

In this tutorial I’m going to show you how to create custom pages in WHMCS. This guide will focus on our professional WHMCS themes but should work with any WHMCS installation/theme/template.

Creating your first WHMCS custom page

Let’s say for example that you would like to create a page called Windows Hosting.

1) Create the page title

The page title is taken from the WHMCS language files which are located at /whmcs/lang/ for example /whmcs/lang/English.php. You will need to add the following code to all of the language files you support (and translate if applicable):

$_LANG[‘windowshosting‘] = "Windows Hosting";

The text highlighted in red is used to reference the page title in the .php file created below. This can be anything you like (no special characters/spaces). To the right of that inside the double quotes is the name of the page.

1) Create the .php page

This page will have all of the functionality required to load the page and assign it the above page title. Luckily this code is provided by WHMCS, however I have simplified their example as much as I could.

Create a new .php file in the root of WHMCS. I always recommend using the page title without spaces and capitations, in this case it will be windows-hosting.php. This file needs to contain the following code:

V5.2 and higher

 <?php
 
 define("CLIENTAREA",true);
 //define("FORCESSL",true); // Uncomment to force the page to use https://
 
 require("init.php");
 
 $ca = new WHMCS_ClientArea();
 
 $ca->setPageTitle("Your Page Title Goes Here");
 
 $ca->addToBreadCrumb('index.php',$whmcs->get_lang('globalsystemname'));
 $ca->addToBreadCrumb('mypage.php','Your Custom Page Name');
 
 $ca->initPage();
 
 //$ca->requireLogin(); // Uncomment this line to require a login to access this page
 
 # To assign variables to the template system use the following syntax.
 # These can then be referenced using {$variablename} in the template.
 
 $ca->assign('variablename', $value);
 
 # Check login status
 if ($ca->isLoggedIn()) {
 
   # User is logged in - put any code you like here
 
   # Here's an example to get the currently logged in clients first name
 
   $result = mysql_query("SELECT firstname FROM tblclients WHERE id=".$ca->getUserID());
   $data = mysql_fetch_array($result);
   $clientname = $data[0];
 
   $ca->assign('clientname', $clientname);
 
 } else {
 
   # User is not logged in
 
 }
 
 # Define the template filename to be used without the .tpl extension
 
 $ca->setTemplate('mypage');
 
 $ca->output();
 
 ?>

V5.1 and lower


<?php

define("CLIENTAREA",true);
//define("FORCESSL",true);

require("dbconnect.php");
require("includes/functions.php");
require("includes/clientareafunctions.php");

$pagetitle = $_LANG['windowshosting'];
$breadcrumbnav = ''.$_LANG['globalsystemname'].'';
$breadcrumbnav .= ' > Windows Hosting';

initialiseClientArea($pagetitle,'',$breadcrumbnav);

if ($_SESSION['uid']) {

$result = mysql_query("SELECT firstname FROM tblclients WHERE id=".(int)$_SESSION['uid']);
$data = mysql_fetch_array($result);
$clientname = $data[0];
$smartyvalues["clientname"] = $clientname;

} else {

# User is not logged in

}

$templatefile = "windows-hosting";

outputClientArea($templatefile);

?>

Focus only on the areas I’ve highlighted in red.

Line 4: If you’d like the page when loaded to use https:// (for a secure SSL connection) instead of http:// remove the 2 backslashes at the start of the line.

Line 10: This line references the page title we created in step 1. As you can see I’ve added windowshosting so it will load Windows Hosting from the language file that the visitor has selected.

Line 12: The first text needs to be the name of this .php file. In this example it is windows-hosting.php. The second is the page name.

Line 29: Lastly this is the name of the .tpl file we’ll be creating in the next step. I recommend using the same name as the .php file. So in this case without the extension it is windows-hosting

3) Create the .tpl file

This last file is where you’ll need to add your content for this particular custom page. It needs to be named exactly in line 35 of the above code but with the .tpl extension. So in this case it is windows-hosting.tpl. This file needs to be created in the following directory:

/public_html/templates/YOUR_TEMPLATE/

As a example add the following basic content to this file:

<h2>This is a page title</h2>

<p>This is a paragraph</p>

4) Viewing the new file

The new file will now be viewable at:

yourdomain.com/windows-hosting.php

You’ve now successfully created your very first custom page!

premium whmcs templates

If you have any questions/problems feel free to leave a comment below.