Style / Edit post display template in Themler per category basis

Stagger Lee
1840 Posts
Stagger Lee posted this 23 April 2015

Theme functions.php or functions.php inside a plugin:
my-category = name of your category where you want detailed post view styled differently.

function get_custom_cat_template($single_template) {
global $post;
if ( in_category( 'my-category' )) {
$single_template = TEMPLATEPATH . '/single-my-category.php';
}
return $single_template;
}
add_filter( "single_template", "get_custom_cat_template" ) ;

If Themler gives you some boring page to style just right click on menus and "Open link" until you get to your post in specific category, then you can style it.

Name custom template in Themler similar to this example adapted to your category slug: single-my-category.php

Theme functions.php or functions.php inside a plugin: **my-category** = name of your category where you want detailed post view styled differently. function get_custom_cat_template($single_template) { global $post; if ( in_category( 'my-category' )) { $single_template = TEMPLATEPATH . '/single-my-category.php'; } return $single_template; } add_filter( "single_template", "get_custom_cat_template" ) ; If Themler gives you some boring page to style just right click on menus and "Open link" until you get to your post in specific category, then you can style it. Name custom template in Themler similar to this example adapted to your category slug: **single-my-category.php**
Vote to pay developers attention to this features or issue.
29 Comments
Order By: Standard | Newest
Support Team
Support Team posted this 11 July 2018

Hello,

Do you mean cusomizing post view in Post and Blog templates separately? For this please select Posts tab >> Customize template style.

Sincerely,
Nettie,
BillionDigital Team

Hello, Do you mean cusomizing post view in Post and Blog templates separately? For this please select Posts tab >> Customize template style. Sincerely, Nettie, BillionDigital Team
phoumanaphensisanavong
1 Posts
phoumanaphensisanavong posted this 11 July 2018

hello, I am interesting this method.
Can you please post the Link for example or link for video present

Thank you,
Phoumana

hello, I am interesting this method. Can you please post the Link for example or link for video present Thank you, Phoumana
Samuele
13 Posts
Samuele posted this 26 February 2018

Hi,

I followed up the instruction above and I managed to change the blog-view template for a specific category... my problem is that the change is then reflected on the single post template. To be more specific the layout for my blog-view template is set in two columns, and this is fine, then when I click to open one of the post also the layout of the post is in two column and therefore my content occupy only half of the space available on screen.

I would like to custom only the post-view for all the post that belongs to a specific category without affecting the blog layout. Is this possible?

I did also try to create from within Themler a new post-template instead of a new Custom-Template, but by doing this I get php error whenever I try to open a post. I get the following error:

include (my_path) failed to open the stream: No such file or directory on (my-path) on line 74.
include(): Failed opening 'my-path....single-post-news.php' for inclusion (include_path='.:/usr/lib/php7.0') in /my-path/wp-includes/template-loader.php on line 74

Anybody out there that can help?

Thanks a lot
Samuele

Hi, I followed up the instruction above and I managed to change the blog-view template for a specific category... my problem is that the change is then reflected on the single post template. To be more specific the layout for my blog-view template is set in two columns, and this is fine, then when I click to open one of the post also the layout of the post is in two column and therefore my content occupy only half of the space available on screen. I would like to custom only the post-view for all the post that belongs to a specific category without affecting the blog layout. Is this possible? I did also try to create from within Themler a new post-template instead of a new Custom-Template, but by doing this I get php error whenever I try to open a post. I get the following error: include (my_path) failed to open the stream: No such file or directory on (my-path) on line 74. include(): Failed opening 'my-path....single-post-news.php' for inclusion (include_path='.:/usr/lib/php7.0') in /my-path/wp-includes/template-loader.php on line 74 Anybody out there that can help? Thanks a lot Samuele
joshpell
28 Posts
joshpell posted this 04 October 2016

You can also use the plugin
https://wordpress.org/plugins/my-custom-functions/
Works great if your worried about loosing your custom functions.

You can also use the plugin https://wordpress.org/plugins/my-custom-functions/ Works great if your worried about loosing your custom functions.
Support Team
Support Team posted this 03 October 2016

Hi,

You can add custom functions to this file in directly Themler >> Home tab >> Settings >> CMS code. This will help to keep the custom code.

Thank you,
Olivia

Hi, You can add custom functions to this file in directly Themler >> Home tab >> Settings >> CMS code. This will help to keep the custom code. Thank you, Olivia
joshpell
28 Posts
joshpell posted this 29 September 2016

Update on my previous comment, you can work on the theme and publish it without it affecting your functions-additional.php HOWEVER if you upgrade your theme all custom functions that you have written will be overwritten so make sure you have a backup of all your custom functions before you update to a new themler version.

Update on my previous comment, you can work on the theme and publish it without it affecting your functions-additional.php **HOWEVER** if you upgrade your theme all custom functions that you have written will be overwritten so make sure you have a backup of all your custom functions before you update to a new themler version.
Support Team
Support Team posted this 23 September 2016

Hello Josh,
thank you for suggestion. It's pretty useful and I'll add it to our wish list

regards,
Aileen

Hello Josh, thank you for suggestion. It's pretty useful and I'll add it to our wish list regards, Aileen
joshpell
28 Posts
joshpell posted this 21 September 2016

In regards to the original post there is under appearance --> editor a php file called functions-additional.php that you can write custom functions into and they will not be overwritten when you update your theme, this is how I just many of the functions for woocommerce.

In regards to the original post there is under **appearance --> editor** a php file called **functions-additional.php** that you can write custom functions into and they will not be overwritten when you update your theme, this is how I just many of the functions for woocommerce.
Stagger Lee
1840 Posts
Stagger Lee posted this 05 August 2015

No. it is something like this:

  • You have one category "Cars"
  • You have another category "Bicycles".
  • This snippet gives you chance to make custom "Post detailed view" templates and have separate styled templates for Cars and Bicycles.

No. it is something like this: - You have one category "Cars" - You have another category "Bicycles". - This snippet gives you chance to make custom "Post detailed view" templates and have separate styled templates for Cars and Bicycles.
RJLevesque
4 Posts
RJLevesque posted this 05 August 2015

Ok, I need to be able to add columns, or blocks in my theme that display posts in a chosen category. Am I to understand this is the code for that? Sorry, I am trying to understand, and no offense but I see a LOT of broken English here so it makes it very hard for me to understand. So is this what I am looking for?

Ok, I need to be able to add columns, or blocks in my theme that display posts in a chosen category. Am I to understand this is the code for that? Sorry, I am trying to understand, and no offense but I see a LOT of broken English here so it makes it very hard for me to understand. So is this what I am looking for?
Stagger Lee
1840 Posts
Stagger Lee posted this 01 June 2015

Just want to expand code from topic opening, to include all nested subcategories:

/** Get Post Category and sub category */
function post_is_in_descendant_category( $cats, $_post = null )
{
    foreach ( (array) $cats as $cat ) {
        // get_term_children() accepts integer ID only
        $descendants = get_term_children( (int) $cat, 'category');
        if ( $descendants && in_category( $descendants, $_post ) )
            return true;
    }
    return false;
}

/** Conditional Templates for Single posts */
function template_change( $template ){

    if( is_single() && (post_is_in_descendant_category('12')) || in_category('12') ){
        $templates = array("single-veg.php");
    }

   elseif( is_single() && (post_is_in_descendant_category('17')) || in_category('17') ){
        $templates = array("single-fruit.php");

    } elseif( is_single() && in_category('articles') ){
        $templates = array("single-articles.php");

    }
    $template = locate_template( $templates );
    return $template;
}

add_filter( 'single_template', 'template_change' ); //'template_include'/'single_template'

Just want to expand code from topic opening, to include all nested subcategories: /** Get Post Category and sub category */ function post_is_in_descendant_category( $cats, $_post = null ) { foreach ( (array) $cats as $cat ) { // get_term_children() accepts integer ID only $descendants = get_term_children( (int) $cat, 'category'); if ( $descendants && in_category( $descendants, $_post ) ) return true; } return false; } /** Conditional Templates for Single posts */ function template_change( $template ){ if( is_single() && (post_is_in_descendant_category('12')) || in_category('12') ){ $templates = array("single-veg.php"); } elseif( is_single() && (post_is_in_descendant_category('17')) || in_category('17') ){ $templates = array("single-fruit.php"); } elseif( is_single() && in_category('articles') ){ $templates = array("single-articles.php"); } $template = locate_template( $templates ); return $template; } add_filter( 'single_template', 'template_change' ); //'template_include'/'single_template'
Stagger Lee
1840 Posts
Stagger Lee posted this 01 June 2015

CMS Code control is used much now on my themes. Very, very nice addition to Themler.
It is robust also. You type, paste wrong code it throws error, reload page and it is gone. Just dont be quick to click Save before Themler analyzed PHP code, wait few seconds.

And I found a way how to add image animations and effects to images, even those on archive/blog lists. All thanks to fact Hover Box control "Hyperlink" parse PHP code right. Good for styling gallery archives. So it is just to paste:

<?php get_permalink($blog_page_id); ?> 

and it is done. Rest is simply to imagination.

CMS Code control is used much now on my themes. Very, very nice addition to Themler. It is robust also. You type, paste wrong code it throws error, reload page and it is gone. Just dont be quick to click Save before Themler analyzed PHP code, wait few seconds. And I found a way how to add image animations and effects to images, even those on archive/blog lists. All thanks to fact Hover Box control "Hyperlink" parse PHP code right. Good for styling gallery archives. So it is just to paste: <?php get_permalink($blog_page_id); ?> and it is done. Rest is simply to imagination.
shaulhadar
455 Posts
shaulhadar posted this 22 May 2015

Hi Stagger, this is great news! I will check it right away :)

Hi Stagger, this is great news! I will check it right away :)
Stagger Lee
1840 Posts
Stagger Lee posted this 21 May 2015

CMS Code control now works as HTML/Text controls, with today update. Thanks, what a relief.

@ shaulhadarm try it now. Piece of cake to insert ACF fields display now. And results are visible directly in Themler edit screen.

CMS Code control now works as HTML/Text controls, with today update. Thanks, what a relief. @ shaulhadarm try it now. Piece of cake to insert ACF fields display now. And results are visible directly in Themler edit screen.

Last edited 21 May 2015 by Stagger Lee

Stagger Lee
1840 Posts
Stagger Lee posted this 19 May 2015

No, it cant be added even in rows and columns if they are in Archive loops. Very dissapointed by this control. But what to do, continue to work manually in PHP files.

This control needs to be where Post category, Post image, Post content, etc...are. Same is for Post/Page templates.

What is interresting HTML and Text controls (blocks) can be added there. So it is maybe just some miss by developers.

No, it cant be added even in rows and columns if they are in Archive loops. Very dissapointed by this control. But what to do, continue to work manually in PHP files. This control needs to be where Post category, Post image, Post content, etc...are. Same is for Post/Page templates. What is interresting HTML and Text controls (blocks) can be added there. So it is maybe just some miss by developers.

Last edited 19 May 2015 by Stagger Lee

Stagger Lee
1840 Posts
Stagger Lee posted this 19 May 2015

This "CMS Code" control is now available.

But seems wont be used for anything useful. Cannot add control inside Archive/Taxonomy/Blog loop or inside Page/Post template.
Just under whole content, ends under comment list.

This "CMS Code" control is now available. But seems wont be used for anything useful. Cannot add control inside Archive/Taxonomy/Blog loop or inside Page/Post template. Just under whole content, ends under comment list.

Last edited 19 May 2015 by Stagger Lee

shaulhadar
455 Posts
shaulhadar posted this 01 May 2015

Yeah, me too, i already have a project that needs lots of custom fields.....

Yeah, me too, i already have a project that needs lots of custom fields.....
Stagger Lee
1840 Posts
Stagger Lee posted this 01 May 2015

I can barely wait this option. Right now I need it for at least 3 different things, on one single website.

I can barely wait this option. Right now I need it for at least 3 different things, on one single website.
jacojashi
52 Posts
jacojashi posted this 30 April 2015

...point for you!

...point for you!
Support Team
Support Team posted this 30 April 2015

You're welcome.

This control will be available in one of the future Themler updates.

You're welcome. This control will be available in one of the future Themler updates.
You must log in or register to leave comments