Specific category single post template

Hi,

I love your theme. I run it on www.tourdoorutrecht.com. Ik do have one question. How can I make a single post template for a specific category? I tried calling it single-category-<slug>.php but it didn’t work. Do you have a solution?

Kind regards,
Rob Vermeulen

I don’t think that there is such thing as single-category-.php in default WordPress template hierarchy.

The thing you might be looking for is this one.

Let me know if this helps.

Hi,

Thanx a lot. I added the code to functions.php. Now it calls ‘single-tourverhaal.php’. That one calls ‘content-tourverhaal’.

The follow up question is: how to remove sidebar and make the content go 100% width. I tried deleting ‘get_sidebar’ but then it only deletes the sidebar but it doesn’t displays the content at 100%.

Do you have the solution? :smiley:

To make single post items full width you can add this code to Appearance >> Theme Options >> Other >> Custom CSS.

.single #content {
  width: 100%;
}

This code will apply only on single blog entries.

Let me know if this is what you were looking for.

Thanx, thought of that though. I need it only to be 100% on a specific single category template. It’s getting harder ;), sorry.

This is slightly more difficult but still duable.

Add this code to Child Theme functions.php or inside Parent Theme functions.php if you don’t use Child Theme.

// add category names for body element
function sparkling_category_id( $classes ) {
	global $post;
	foreach ( get_the_category( $post->ID ) as $category ) {
		$classes[] = $category->category_nicename;
	}
	return $classes;
}
add_filter( 'body_class', 'sparkling_category_id' );

Now WordPress will print category name as class for <body> element.

So you will be able to target it like this via CSS:

.your-category-name .single #content {
  width: 100%;
}

Let me know if this helps.

unfortunately it didn’t work. I just leave it the way it is. Can’t be done without proper knowledge on my part.

If you are still on it then try to tweak CSS like this:

.tourverhaal .single #content {
  width: 100%;
}

And take PHP code from above as I made slight change in it.

Let me know if this helps.

This is a example page which should be wide:

As you see it still doesn’t work. I added your improved php to the functions.php. I added the css to the Theme Options css-panel. Still nothing. I do not want to be a time consuming customer so I hope you dont mind me asking you for all this help ;). Here is the code of my template page:

<?php
/**

 *
 * @package sparkling
 */

get_header('wide'); ?>

	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">

		<?php while ( have_posts() ) : the_post(); ?>

			<?php get_template_part( 'content', 'tourverhaal' ); ?>

			<?php
				// If comments are open or we have at least one comment, load up the comment template
				if ( comments_open() || '0' != get_comments_number() ) :
					comments_template();
				endif;
			?>

			<?php sparkling_post_nav(); ?>

		<?php endwhile; // end of the loop. ?>

		</main><!-- #main -->
</div></div><!-- #primary -->

<?php get_footer(); ?>

Hmm… nothing helps. You mind taking a look on my wordpress? Then you see how I did it.

For the sake of I don’t know here is how I did things:

I told functions.php to take single-tourverhaal.php as the template-file. That works.

In single-tourverhaal.php I call content-tourverhaal.php.

In functions.php I put in your slightely changed code. In options-panel I added the css you just gave me.

Sometimes life is a donkey ;).

Maybe I could give you my credentials? I would even like to pay you for it.

Now that I see CSS category printed in your website source sine you have added my above mentioned code. You can use this CSS to make your posts full width.

.single.tourverhaal #content {
  width: 100%;
}

You will still have to get rid of sidebar but if I remember correctly, then you knew how to do it before.

Hero. Thanx a lot. I don’t know why you would invest so much time in everyones questions but It makes you hero of the day.

No problem at all. Glad I could help :slight_smile:

It depends on questions. I hate answering the same questions that have been asked dozens of times before and user didn’t care to do a quick search. Your question were completely new and no one have asked anything like this before, so I wanted to learn something new for myself as well.