2017-09-12, 03:58:36
(2017-08-22, 05:33:41)carpman Wrote: Is it possible to have different template files for different kinds of posts, as per:
single templateFile template-blog-post.php
But perhaps determined by tag, so for example, for image based posts I'd like to use one kind of template, for text based posts another. So I'd like to have a tag "image" and a tag "text" and depending which tag the post has, a different template file is used.
Something like this in custom settings?
single templateFile tag="text" template-blog-post-text.php
single templateFile tag="image" template-blog-post-image.php
Is this possible currently?
I'm not bothered about method (as per above), just whether this can be done at present.
Many thanks,
C.
Create a new template file (e.g. template-blog-single.php) with this contents:
PHP Code:
<?php if(!defined('IN_GS')){ die('you cannot load this page directly.'); }
function custom_include_template($temp) {
global $TEMPLATE;
$file = GSTHEMESPATH.$TEMPLATE.'/'.$temp;
if (file_exists($file)) include $file;
}
if (nm_post_has_tag('text')) {
custom_include_template('template-blog-post-text.php');
} elseif (nm_post_has_tag('image')) {
custom_include_template('template-blog-post-image.php');
} else {
custom_include_template('template-blog-post.php');
}
// end
Now in NM Custom Settings, select it with:
Code:
single templateFile template-blog-single.php
PS I suggest you use the .inc.php extension instead of just .php for these "special templates" so that they cannot be selected for normal pages by your users.