- This topic has 8 replies, 2 voices, and was last updated 4 years, 7 months ago by Rodrigo.
-
AuthorPosts
-
October 9, 2016 at 7:55 pm #233926Rodrigo
Hi Tom,
How can I create a custom single post template for a specific category?
In single posts within a specific category I’d like to change the featured image smaller and to the right and put the title and content next to it.
That specific post is just going to have a paragraph description and a player for podcast.
Is there a plugin or somehow I can do that?
October 9, 2016 at 8:57 pm #233936TomLead DeveloperLead DeveloperYou 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 ๐
October 9, 2016 at 10:18 pm #233950RodrigoUh WOW, that worked perfectly well…
I might need a little bit of help, if you can.
How can I put the image below the title, so that way the title size will be 100% of the content area?
October 9, 2016 at 11:06 pm #233957TomLead DeveloperLead DeveloperYou should be able to do that in “Customize > Layout > Page Header” by changing “Single Post Page Header” to “Below title”.
Let me know ๐
October 10, 2016 at 12:00 am #233962RodrigoThe thing is I only need that image position in one unique category posts. On the other categories, image’s posts should be above any element, including post title.
October 10, 2016 at 9:35 am #234068TomLead DeveloperLead DeveloperThat’s a bit harder, but you should be able to do this:
add_action( 'after_setup_theme','tu_category_specific_page_header' ); function tu_category_specific_page_header() { // Only do this if we're in category IDs 1, 2 and 3 if ( in_category( array( 1,2,3 ) ) ) { remove_action('generate_after_header','generate_page_header_single_above', 10); add_action('generate_after_entry_header','generate_page_header_single_below_title', 10); } }
January 10, 2019 at 11:46 am #778598RodrigoI guess this is solved with the new Elements module on GP, right?
January 10, 2019 at 4:41 pm #778773TomLead DeveloperLead DeveloperWhich part, specifically?
August 28, 2019 at 10:15 pm #995968RodrigoHello Tom. I’m just gonna close this thread because I can’t even remember what site I was talking about here (and if is still on my hands, which I don’t think so) and, honestly, I don’t like to see the topic open. You know, OCD issues… n_n
-
AuthorPosts
- You must be logged in to reply to this topic.