Wordpress - Custom page and post templates


Default page and post templates

The default page and post templates are to be placed under /app/view/wordpress/page.html and /app/view/wordpress/post.html and you will have access to the current WpPost/WpPage object as {{wp.post}}. Like in regular WordPress, this template is loaded when you type in the slug of a page or post respectively. See the docs for details on the properties. You can also use WordPress tags, though the object property method is recommended.

The default templates can be found under /plugins/wordpress/view/*.html and you can use this as a starting point.

Creating custom templates for pages and posts

The Outlast Framework Custom Template plugin is included with the WordPress plugin and is automatically enabled (in the mu-plugins folder). With it, you can set the template of any post or page to specific OFW template or you can reroute to an OFW controller.

First, let’s see how a template is registered. Just include the following in your __wpload() method:

$this->zajlib->wordpress->register_template(array(
  'id'=>'framework_plugins',
  'name'=>'Framework - Plugins',
  'template'=>'plugins.html'
));

Once this has been added, an option to choose this custom template will appear in the WordPress admin interface. If set to the template defined here, WordPress will display the plugins.html template (this template is relative to the /view/ folder of your OFW app or plugins) where you can use all of the features that standard framework template system files enjoy (variables, tags, inheritance, etc.)

Creating custom controllers for pages and posts

Very similar to registering templates, you can also register controllers to handle page and post output. This is useful if you want to run code before the template is displayed (such as fetching items from the database, etc.).

To register controllers, just include the following in your __wpload() method:

$this->zajlib->wordpress->register_template(array(
  'id'=>'framework_plugins',
  'name'=>'Framework - Plugins',
  'reroute'=>'/wptemplate/example/'
));

Once this has been added, an option to choose this custom template will appear in the WordPress admin interface. If set to the template defined here, WordPress will reroute the request to the controller before the template is displayed. Here you can perform any actions necessary before you call the usual $this->zajlib->template->show('your_template.html'); to display the output.

For organization, it is recommended (though not required) to place templates in a separate controller, such as wptemplate.ctl.php.

Adding custom themes and plugins to wp-content

In order to add themes and/or plugins to the Outlast Framework’s WordPress, you will need a “local” copy of wp-content. Here’s how to do it:

  1. copy /plugins/wordpress/site/wp-content/ to /plugins/_project/site/wordpress/wp-content/
  2. delete all the plugins and themes you do not need
  3. make sure that the file /plugins/wordpress/site/.htaccess with the code RewriteEngine off
  4. uncomment the first WordPress-related row in the /.htaccess file

Typically it is not recommended to use “standard” WordPress themes, since you lose the possibilities afforded by the Outlast Framework’s template system and data model system.

[RÉGI MAGYAR DOKSI ALÁBB: FRISSÍTENI!]

Post-ok/Page-ek saját template-jei

  1. Page template regisztrállása a default.ctl.php __wpload() függvényében, ld. példa.
  2. Page html létrehozása szokásos blockos módszerrel az app/view/wordpress mappába. Itt egy példa. A post-ok/page-ek adatstruktúrájáról itt találsz leírást.
  3. WP-adminban page létrehozása, custom template beállítása (jobb oldalt kell kiválasztani). A page urljén már be is jön a tartalom.

Fontos! Minden egyedi beállítás ami a __wpload() függvényben készül csak abban az esetben aktiválódik ha a “Mozajik Light” template-et használod és ezt állítod be aktív WordPress template-ként.

 

Barátságos 404

Az alábbi kód egy barátságos 404-es oldalt jelenít meg.

/**
 * Errors are processed as valid requests
 **/
 function __error($request, $optional_parameters){
 // nothing found
 header("HTTP/1.1 404 Not Found");
 if(file_exists($this->zajlib->basepath.'app/view/404.html')) $this->zajlib->template->show('404.html');
 else echo "The page $request could not be found.";
 exit();
 }
Outlast Web & Mobile Development (c) 2023 | Privacy Policy |