Style / Edit post display template in Themler per category basis

Stagger Lee
1774 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.
26 Comments
Order By: Standard | Newest
Stagger Lee
1774 Posts
Stagger Lee posted this 23 April 2015

Worth noting, Themler will delete all your code inside theme functions.php on each Save inside Themler.
Search on Google how to put another functions.php inside a plugin. It is very easy. And work on it functions.php.

Worth noting, Themler will delete all your code inside theme functions.php on each Save inside Themler. Search on Google how to put another functions.php inside a plugin. It is very easy. And work on it functions.php.
Support Team
Support Team posted this 28 April 2015

Hello Stagger Lee,
natively WP does not support different styles for different categories, so we suppose that it worth to implement this feature as custom control or via custom code. It is in our plans to add special field under Theme Settings that allows enter custom code for CMS. So it would be possible to add custom PHP code for WP.

Regards,
Aileen

Hello Stagger Lee, natively WP does not support different styles for different categories, so we suppose that it worth to implement this feature as custom control or via custom code. It is in our plans to add special field under Theme Settings that allows enter custom code for CMS. So it would be possible to add custom PHP code for WP. Regards, Aileen
Stagger Lee
1774 Posts
Stagger Lee posted this 28 April 2015

Thanks. Give us option to put PHP code inside HTML block, Text block.

Thanks. Give us option to put PHP code inside HTML block, Text block.
shaulhadar
400 Posts
shaulhadar posted this 29 April 2015

I want the php in html as well! :)

I want the php in html as well! :)
Support Team
Support Team posted this 29 April 2015

Hello Stagger Lee,
I'm very sorry for the inconvenience, there is elaboration for my previous post regarding WP categories: In fact WP does not support custom templates for single posts in certain category (but not "different styles for different categories" as I wrote before).

As it would be possible to implement it in theme via custom PHP code the ability to add PHP under Theme Settings will be helpful.

Regards,
Aileen

Hello Stagger Lee, I'm very sorry for the inconvenience, there is elaboration for my previous post regarding WP categories: In fact WP does not support custom templates for single posts in certain category (but not "different styles for different categories" as I wrote before). As it would be possible to implement it in theme via custom PHP code the ability to add PHP under Theme Settings will be helpful. Regards, Aileen
Stagger Lee
1774 Posts
Stagger Lee posted this 29 April 2015

OK Aileen, thanks.

PHP code inside HTML blocks is something different. Cannot open more topics, only me write here at forum. Tend to be boring for other Users.

PHP code inside HTML blocks for, some examples:

  • Output of custom fields.
  • Putting shortcodes in theme via PHP.
  • I use my own PHP snippets to check if post has gallery, video, audio, oembed, attachments, etc. According to this I display small SVG icon in Blog list.
  • We could put call for a template file to reduce need for widgets. Littole special customization, but...See my theme here:
    http://answers.billiondigital.com/questions/10934/one-feature-that-would-make-themler-killer

  • We could output code of plugins where we want. Directly in template file to eliminate need for inserting shortcodes in editor. (one example review/Rating/voting stars in Blog and detailed view, or code for content views code.

It is basically only a fraction of things we could make if we could put PHP code in HTML blocks (Insert option).

Of course with some basic PHP validation check to prevent Themler show blank page and fatal errors. There is already validation inside Theme settings option, just reuse it,

OK Aileen, thanks. PHP code inside HTML blocks is something different. Cannot open more topics, only me write here at forum. Tend to be boring for other Users. PHP code inside HTML blocks for, some examples: - Output of custom fields. - Putting shortcodes in theme via PHP. - I use my own PHP snippets to check if post has gallery, video, audio, oembed, attachments, etc. According to this I display small SVG icon in Blog list. - We could put call for a template file to reduce need for widgets. Littole special customization, but...See my theme here: [http://answers.billiondigital.com/questions/10934/one-feature-that-would-make-themler-killer][1] [1]: http://answers.billiondigital.com/questions/10934/one-feature-that-would-make-themler-killer - We could output code of plugins where we want. Directly in template file to eliminate need for inserting shortcodes in editor. (one example review/Rating/voting stars in Blog and detailed view, or code for content views code. It is basically only a fraction of things we could make if we could put PHP code in HTML blocks (Insert option). Of course with some basic PHP validation check to prevent Themler show blank page and fatal errors. There is already validation inside Theme settings option, just reuse it,
Support Team
Support Team posted this 30 April 2015

Hi,

Our developers discussed your request and decided to add new control similar to existing HTML control, which allows to execute custom php.
The final version of this control might look a little differently but here is it:

cms-code.png

Thank you,
Olivia

Hi, Our developers discussed your request and decided to add new control similar to existing HTML control, which allows to execute custom php. The final version of this control might look a little differently but here is it: !cms-code.png! Thank you, Olivia
Stagger Lee
1774 Posts
Stagger Lee posted this 30 April 2015

Exactly this, thank you,

Exactly this, thank you,
shaulhadar
400 Posts
shaulhadar posted this 30 April 2015

Wow Olivia, this is amazing, this means that like stagger lee wrote, we could use acf hooks straight inside themler!!!!

Thank you so much for that!!

Wow Olivia, this is amazing, this means that like stagger lee wrote, we could use acf hooks straight inside themler!!!! Thank you so much for that!!
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.
jashi
52 Posts
jashi posted this 30 April 2015

...point for you!

...point for you!
Stagger Lee
1774 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.
shaulhadar
400 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
1774 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

Stagger Lee
1774 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
1774 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

shaulhadar
400 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
1774 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.
Stagger Lee
1774 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'
rjlemail
3 Posts
rjlemail 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?
You must log in or register to leave comments