• Hello,

    I’d like to be able to change background colour of posts based on their category, and based on my research I understand that post_class function is what I need to use:

    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

    I’m editing single.php file of my Ippo child theme. I’ve been unsuccessful so far in understanding where exactly the div + function should go.

    My theme is Ippo (child), and the single.php file looks like this:

    <?php
    /**
     * The template for displaying all single posts.
     *
     * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
     *
     * @package Ippo
     */
    
    get_header(); ?>
    	
    	<div class="container container-medium">
    
    		<?php while ( have_posts() ) : the_post(); ?>
    
    			<div class="hero clear">
    		    	<!-- Featured media -->
    		    	<?php ippo_featured_media(); ?>
    
    		    	<div class="entry-header">
    		    		<!-- Entry header -->
    		    		<?php ippo_entry_header( 'single' ); ?>
    	    		</div>
    			</div>
    
    			<div class="row">
    
    				<div id="primary" class="content-area <?php ippo_content_classes(); ?>">
    					<main id="main" class="site-main" role="main">
    
    						<div class="container container-small">
    
    							<?php get_template_part( 'templates/template-parts/content', get_post_format() ); ?>
    
    						</div><!-- .container.container-small -->
    
    						<?php
    
    							// Author box
    							ippo_author_box();
    
    							// Post navigation
    							ippo_post_navigation();
    
    							// Related posts
    							ippo_related_posts();
    
    							// If comments are open or we have at least one comment, load up the comment template.
    							comments_template();
    
    						?>
    
    					</main><!-- #main -->
    				</div><!-- #primary -->
    
    				<?php get_sidebar(); ?>
    
    			</div><!-- .row -->
    
    		<?php endwhile; // End of the loop. ?>
    
    	</div><!-- .container.container-medium -->
    
    <?php
    
    get_footer();

    I’ve already changed the style.CSS to include:

    .category-SPRING {background: #000000; border: 1px solid #FFFFFF;}

    And on the WP site have a post under category SPRING.

    I’d appreciate any suggestions! Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Where to insert post_class function in WordPress single.php file?’ is closed to new replies.