Reply To: Custom template for Single post

Home Forums Support Custom template for Single post Reply To: Custom template for Single post

Home Forums Support Custom template for Single post Reply To: Custom template for Single post

#233936
Tom
Lead Developer
Lead Developer

You may not need a custom template.

You would need to add the category class to the single post though with a function like this:

add_filter('body_class','add_category_to_single');
function add_category_to_single($classes, $class) {
    if (is_single() ) {
        global $post;
        foreach((get_the_category($post->ID)) as $category) {
            // add category slug to the $classes array
           $classes[] = $category->category_nicename;
        }
    }
    // return the $classes array
    return $classes;
}

Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/

Then you could target that featured image like this:

.your-category-name .page-header-image-single {
    max-width: 300px;
    float: right;
}

Adding CSS: https://generatepress.com/knowledgebase/adding-css/

That should get you started 🙂