Support » Theme: Hueman » Custom single post template for specific category

  • itslori

    (@itslori)


    Hello,

    I would like to use a custom single post template for a specific category and am having a little trouble. My template file is not being recognized and continues to use the default template file. Purpose: show a default category image as the featured image for single posts in a specific category.

    I am using a child theme and attempting to keep everything as simple and straightforward as possible with the least amount of changes. I do have a custom single-tmpl file in the child folder and it’s worked very well (needed feat. images on the single post pages). I realize I can continue to edit single-tmpl to show either feat. img or my fallback category image (this is working well so far) but for further customizations, I would like the category to have it’s own custom single post template, if possible. The basic code doesn’t seem to work with Hueman.

    The single-tmpl adjustment only required a simple file edit, but for custom templates, I’ve had to add a filter in functions.php, create a new template, then call my custom tmpl file from inside that template, and this is where it gets tricky and the file is not recognized (the code inside the custom tmpl file itself has not been an issue). Is there a special file naming format for additional template files? Or better yet, a simpler way to tackle this altogether?

    Thank you for your time.

Viewing 4 replies - 1 through 4 (of 4 total)
  • itslori

    (@itslori)

    Update:

    As much as I hate to edit a parent theme file, I’ve edited the function: “hu_is_authorized_tmpl” in file: functions/init-front.php to include (authorize) my custom tmpl file. Of course, it works, but this is far from ideal, especially as Hueman is updated very frequently (https://themes.trac.wordpress.org/log/hueman).

    I attempted first to override the function with remove_filter (done the proper way to ensure it’ll override the parent?), and this may be the best method to achieve what I need. It didn’t work, however, and I’m hoping it’s a simple mix-up in how I’ve set the overriding function up (likely!).

    function my_hu_is_authorized_tmpl( $tmpl ) {
        $ct_map = apply_filters(
            'hu_content_map',
            array( 'tmpl/index-tmpl', 'tmpl/archive-tmpl', 'tmpl/page-tmpl', 'tmpl/single-tmpl', 'tmpl/search-tmpl', 'tmpl/404-tmpl', 'tmpl/MYCUSTOMTEMPLATEFILE-tmpl' )
        );
        //Are we good after filtering ?
        if ( ! is_array( $ct_map ) || ! is_string( $tmpl ) )
          return;
        return in_array( $tmpl, $ct_map );
    }
    
    function my_child_theme_setup() {
        remove_filter( 'hu_is_authorized_tmpl', 'hu_content_map' );
        add_filter( 'hu_is_authorized_tmpl', 'my_hu_is_authorized_tmpl' );
    }

    Of note, I agree with the poster of the topic “Custom post type templating issues” on several points. I think we use WP so differently that even themes need to be highly customizable and with few restrictions. I may switch to a CPT for this specific category and will also need to know how best to add a CPT template within Hueman. This is a wonderful theme — one of the best available — but I’m just currently stuck. Input is appreciated.

    Hi, I’m having a similar issue, with a custom post type. I created a child theme, and over there proceeded to create custom single and archive templates for my resource type. Unfortunately hueman outsources the functions to the tmpl/ and parts/ folders. After some tracing I managed to find hu_is_authorized_tmpl function defined in the functions/init-front.php file. I made a copy of it in my child theme and edited it, to include my custom post type’s templates that I created in the tmpl/ folder of my child theme. As per this documentation it’s supposed to look in the child theme for the replacement. Instead it seems to be ignoring my new init-front.php and using the old one only. I’m now going to try and define this function afresh in the functions.php of my child theme as advised in the documentation.

    GOTCHA! I re-defined the hu_is_authorized_tmpl function in my child theme’s functions.php. My site went white-screen, but thanks to the error log created in my site’s root dir, I’ve now confirmed that the hueman theme is loading functions/init-front.php from the PARENT theme instead of the CHILD theme. They left this function “unplugged”, so I had to edit the parent theme’s functions/init-front.php to make it “pluggable”, as defined in their documentation. My customizations are now working fine 🙂 Hope this helps others.

    Error log:

    [30-Dec-2017 16:48:16 UTC] PHP Fatal error: Cannot redeclare hu_is_authorized_tmpl() (previously declared in /..path../wp-content/themes/hueman-tropicsu/functions.php:11) in /..path../wp-content/themes/hueman/functions/init-front.php on line 56

    pluggable function in functions/init-front.php in the parent theme:

    if( ! function_exists('hu_is_authorized_tmpl') ) {
      function hu_is_authorized_tmpl( $tmpl ) {
        $ct_map = apply_filters(
            'hu_content_map',
            array( 'tmpl/index-tmpl', 'tmpl/archive-tmpl', 'tmpl/page-tmpl', 'tmpl/single-tmpl', 'tmpl/search-tmpl', 'tmpl/404-tmpl' )
        );
        //Are we good after filtering ?
        if ( ! is_array( $ct_map ) || ! is_string( $tmpl ) )
          return;
        return in_array( $tmpl, $ct_map );
    }
    }

    He hecho lo de conectar en el archivo init-front.php pero no me funciona mi custom post type :/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom single post template for specific category’ is closed to new replies.