Skip to content

Create custom page template

Robert Isoski edited this page Oct 9, 2022 · 5 revisions
  1. To create a custom page template you will need an extra file in your current theme directory with the new CSS file you want to apply.
  • For example, if you want to have a custom theme for your page named home, you need to create a home.php file in your current theme directory themes/yourTheme/home.php
  • If you want to create a custom theme for another page that you have named example, the custom file will have to be named example.php

To make this easier, create a copy of your theme.php file and rename it to home.php or any other page that already exists (example.php)

  1. Replace CSS style with the one you wish to apply to the home or example page and leave everything else as it, unless you also want to change the page structure.

IMPORTANT: Your custom page template will only load if your the page exists and if the slug is the same. Example slug: your-long-page slug will have to have a file named your-long-page.php in your currently active theme directory.


Solution 2 provided by ctuxboy

<?php
  // get current $dir
  $dir = pathinfo($Wcms->getCurrentPageUrl(), PATHINFO_DIRNAME);
  $pattern = '/employees/';

  // if 'employees' in the url => profile-page-layout ELSE default layout
  if (preg_match($pattern, $dir)) {
    echo 'EMPLOYEE PAGE!'; // add here your specific template/layout
  } else {
    echo 'DEFAULT PAGE!'; // default template/layout
  }
?>
Clone this wiki locally