Jump to content

Create new nested page OR page in sub-folder


USA_Webmaster

Recommended Posts

mydomain.com/website (landing page)

mydomain.com/website/web-design (option a)

mydomain.com/website/web-development (option b)

 

May you please share with me how to create a nested page?

May you please share with me how to create a page inside of a folder?

 

The .php file in root directory defined template filename without .tpl looks like this:

 

$ca->setTemplate('/website/web-design');

 

When I visit my newly created page, error 404 shows up. The creating page wiki has proved to be very helpful...on multiple occasions. This is my 5th custom page I've created, so I know I'm doing some of the steps correctly. With your guidance I hope to achieve the results I desire.

 

Thanks in advance for your attention and Happy Sunday!

 

p.s. - when I type "whmcs new page subfolder OR nested" into google / bing i'm just seeing results about migrating the WHMCS install.

Link to comment
Share on other sites

This is a good question, I haven't seen this achieved before but I've always wanted to know if it's possible. Hopefully someone will chime in who's managed to test this.

 

It's probably possible using htaccess but it would be better if it was possible this way.

Link to comment
Share on other sites

taking the example code from http://wiki.whmcs.com/Creating_Pages

 

<?php

use WHMCS\Database\Capsule;

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', Lang::trans('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

 $clientName = Capsule::table('tblclients')
     ->where('id', '=', $ca->getUserID())->pluck('firstname');

 $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();

now that works fine in the root, but if you want to create a nested page, then you would need to change a few file paths...

 

let's say the above code works fine @ demo.whmcs.com/test.php;

if we wanted to have a page at demo.whmcs.com/brian/test.php, we would make these changes...

 

<?php

use WHMCS\Database\Capsule;

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', Lang::trans('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

 $clientName = Capsule::table('tblclients')
     ->where('id', '=', $ca->getUserID())->pluck('firstname');

 $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();

there are only three changes to the code - the breadcrumb paths and the path to init.php... I assume, but untried(!), that if you nested a page at demo.whmcs.com/brian/zomex/test.php, then you would just add an additional '../' to the three paths...

 

i've just tried this on the "Six" template, and one obvious issue that I ran into was that on the nested pages, the navbar links are wrong and try to link to pages in the "brian" directory rather than root - the quick fix for that would be to add the code below to the top of "templates/six/includes/navbar.tpl".

 

<base href="{$systemurl}">

it's possible you may need to use similar code on other includes (sidebar.tpl?) depending on what the output of these pages is.

 

if you wanted to have folders within the "six" template to match the main site subfolders and link to these templates in your php file, you can do... the code below would use the 'test.tpl" template within the "templates/six/brian/" folder.

 

$ca->setTemplate('brian/test');

...depending on what you're trying to do in the templates, you may run into path issues, but <base> may get you out of trouble if that occurs.

Edited by brian!
Link to comment
Share on other sites

  • 3 weeks later...

I realy didnt understan this, pls can you throw more light on it.

 

When i want to create whmcs.com/test.php; i normally do the below

 

1. I create test.php in my root directing, using the format in http://wiki.whmcs.com/Creating_Pages

2. I create test.tpl in my custom whmcs theme at public_html/templates/mywebsitetheme/test.tpl

 

after doing the above, them i can access whmcs.com/test.php

 

NOW i want to create the below

 

A. whmcs.com/hosting/ and whmcs.com/hosting/index.php

B. whmcs.com/hosting/freetest.php

C. whmcs.com/hosting/good and whmcs.com/hosting/good/index.php

D. whmcs.com/hosting/good/quality.php

E. whmcs.com/hosting/good/using-ftp.php and whmcs.com/hosting/good/using-ftp.php/index.php

F. whmcs.com/hosting/good/using-ftp.php/quality.php

 

So how and where do i create the php and tpl files?

what are the codes i should put in the php and tpl files?

 

Please some one should help quickly, thanks

Link to comment
Share on other sites

for A & B, just use the second block of code I posted in the above thread - it's exactly the same as the first block of code (taken from the Creating Pages page that you're already using - except i've changed the three paths and added '../' to them - the reason for doing that is because those files it's using are in the root WHMCS folder, so it needs to know where to find them.

 

for C, D and 1st part of E, it's the same code again, but just change those 3 paths and add another '../'

 

require("../../init.php");
$ca->addToBreadCrumb('../../index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('../../mypage.php', 'Your Custom Page Name');

 

for 2nd half of E and F, it's the same code again, but just change those 3 paths and add another '../'

 

require("../../../init.php");
$ca->addToBreadCrumb('../../../index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('../../../mypage.php', 'Your Custom Page Name');

so you create the .php files where you want them to be - e.g in the 'hosting' folder, or the 'hosting/good/' folder etc...

 

the templates go in templates/Six (or the name of your custom template) - you don't need to make subfolders in your templates folder for these new pages - you can do, but if you do, you must use the path in the line below and replace 'brian' with your template subfolder...

 

$ca->setTemplate('brian/test');  

if that sounds too complicated, just keep it simple and put them all in the templates/Six (or the name of your custom template) folder. :idea:

 

to hide index.php files, that's more of a task for .htaccess... solution below, but it's worth Googling more information about .htaccess as it's a useful feature to learn about.

 

https://forum.whmcs.com/showthread.php?101179-How-to-remove-index-php-from-my-url-using-htaccess&p=419523#post419523

Link to comment
Share on other sites

At brian!, i have applied all you said, but they dont seem to be working.

1. Pls what you posted here, have you tried them out before?

2. Can you pls mail me so that i can send you all the links for you to see that they are not working and help me check what the error could be, i try to mail you privately, but whmcs forum wont allow me. Pls my email is hostmonitorsATgmail.com

Pls i need it so so urgently

3. Do you have a web hosting company or are you working for whmcs or are you a freelancer

 

Waiting to hear from you soon, thanks

 

for A & B, just use the second block of code I posted in the above thread - it's exactly the same as the first block of code (taken from the Creating Pages page that you're already using - except i've changed the three paths and added '../' to them - the reason for doing that is because those files it's using are in the root WHMCS folder, so it needs to know where to find them.

 

for C, D and 1st part of E, it's the same code again, but just change those 3 paths and add another '../'

 

require("../../init.php");
$ca->addToBreadCrumb('../../index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('../../mypage.php', 'Your Custom Page Name');

 

for 2nd half of E and F, it's the same code again, but just change those 3 paths and add another '../'

 

require("../../../init.php");
$ca->addToBreadCrumb('../../../index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('../../../mypage.php', 'Your Custom Page Name');

so you create the .php files where you want them to be - e.g in the 'hosting' folder, or the 'hosting/good/' folder etc...

 

the templates go in templates/Six (or the name of your custom template) - you don't need to make subfolders in your templates folder for these new pages - you can do, but if you do, you must use the path in the line below and replace 'brian' with your template subfolder...

 

$ca->setTemplate('brian/test');  

if that sounds too complicated, just keep it simple and put them all in the templates/Six (or the name of your custom template) folder. :idea:

 

to hide index.php files, that's more of a task for .htaccess... solution below, but it's worth Googling more information about .htaccess as it's a useful feature to learn about.

 

https://forum.whmcs.com/showthread.php?101179-How-to-remove-index-php-from-my-url-using-htaccess&p=419523#post419523

Link to comment
Share on other sites

At brian!, i have applied all you said, but they dont seem to be working.

1. Pls what you posted here, have you tried them out before?

nearly every bit of code that I post here is tested before posting - so the above certainly works on the first subfolder, whether it works on the second+ levels, I never tested (as stated in the post)... though no-one else has told me it doesn't!

 

2. Can you pls mail me so that i can send you all the links for you to see that they are not working and help me check what the error could be, i try to mail you privately, but whmcs forum wont allow me. Pls my email is hostmonitorsATgmail.com

you need five posts before you can enable the PM system - email sent.

 

3. Do you have a web hosting company or are you working for whmcs or are you a freelancer

in the order that you asked them: yes - no - and yes (if the project interests me!). :)

Link to comment
Share on other sites

ok, i've tested this locally down to two levels, using "Five" and "Six" templates and it does work! :idea:

 

let's say we want to add index.php to demo.whmcs.com/hosting/good/ - you would create index.php in that folder and add the code below to it...

 

<?php

define("CLIENTAREA",true);
//define("FORCESSL",true); // Uncomment to force the page to use https://

require("../../init.php");

$ca = new WHMCS_ClientArea();

$ca->setPageTitle("nested pages example");

$ca->addToBreadCrumb('../../index.php',$whmcs->get_lang('globalsystemname'));
$ca->addToBreadCrumb('index.php','nested page breadcrumb'); 

$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('brianblank');

$ca->output();

?>

the important part is getting the path back to init.php correct - if you do, this will work; if it's wrong, you'll get a blank page.

 

also, the first breadcrumb links back to the WHMCS homepage (Portal Home) and will likely need the same path as init.php; the second breadcrumb link links back to itself, so shouldn't require any changes.

 

the above example just uses a basic template file - brianblank.tpl - which just outputs a simple text message to the screen.

 

Hello World, This is brian!

 

r1sA3UK.png

 

this will work, but as I stated before, the menu navbar link paths would be wrong - e.g the "Announcements" link would point to...

 

demo.whmcs.com/hosting/good/announcements.php

my previous fix for this was to add a <base href> to navbar.tpl - what might be a better solution for custom templates, is to add it inside the <head> section of header.tpl instead - either directly in the template or via an action hook.

 

<base href="{$systemurl}">

if you don't want to edit the header.tpl template, e.g to avoid adding it again after every WHMCS update, you can add it automatically using an action hook...

 

create a file in /includes/hooks, call it nestedhead.php and add the following code into it.

 

<?php

function nested_pages_basehref_hook($vars) {

   $systemurl = $vars['systemurl'];
   $head_return = '<base href="'.$systemurl.'"/>';
   return $head_return;
}
add_hook("ClientAreaHeadOutput",1,"nested_pages_basehref_hook");

you may need to experiment to find a solution to this depending upon the complexity of your template, e.g if using <base href >interferes with other features...

 

when using the "Six" theme, adding <base href> to header.tpl can interfere with the login/language dropdowns in the notification area - even adding it to navbar.tpl seems to have the same effect... so for themes based on "Six", you might need to play with this further... I guess if you don't want to mess with the includes templates, you could simply write an action hook to replace the navbar link URLs with absolute links... or simply don't nest the pages! :)

 

@hostmonitor - your issue is caused by you not adding a <base href> to your custom template as per the instructions - if you add it to header.tpl, then it should start to work... :idea:

 

gvh8MUN.png

Link to comment
Share on other sites

Creating the SEO for the nested page, how do i fix it

 

I used the guide at the thread to create a folder and a page like whmcs.com/hosting/freetest.php

 

NOW I AM HAVING ISSUE WITH THE SEO,

1. How do i add meta title page

2. How to i add meta description

3. How do i add other SEO related things that i might want to put

 

Please urgrnt help is needed

 

Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated