Skip to content

Use Page Template feature

Alessandro Fazzi edited this page Jan 11, 2021 · 4 revisions

If you're using older version of Wordless, please refere to past revisions of this page.

Make a folder in theme's root named page-templates and create a consistently named php file

mkdir page-templates
touch page-templates/static.php

and write it as follow

<?php
/*
* Template Name: Static
*/

include(get_template_directory() . '/index.php');

Write down an ad-hoc layout, e.g. theme/views/layout/static.html.pug

doctype html
html
  head
    include /layouts/head.pug/
  body
    .page-wrapper
      header.site-header
        | This is my static layout with a static title in the header
      section.site-content
        block yield
      footer.site-footer
        include /layouts/footer.pug

    // jQuery and application.js is loaded by default with wp_footer() function. See config/initializers/default_hooks.php for details
    - wp_footer()

and a template of your wish extending the static layout, e.g. theme/views/templates/single_static.html.pug:

extends /layouts/static.pug

block yield
  h2 Post Details
  - the_post()
  include /partials/post.pug

then in your router you can control as you wish

/* ./index.php */
if (is_page_template("page-templates/static.php")){
    render_template('templates/single_static');
}