Adding a class to a post entry in Genesis child theme

· 2 min read

Creating a page that will list posts of a certain category. I want to add some classes to each entry so that it will format them in these colored boxes created using css and used in other parts of the website. I didn't want to the user to have to type in the markup or have to use a shortcode to surround the post. It also alternates color so they user isn't going to know what color to use for each post. I could have used the nth-child selector but finding too many issues with older browsers anyway. Created a page-agents.php file and created a wordpress page with the slug: agents. The last section of this code adds the classes I wanted to each entry


 3, 'posts_per_page' => 5, 'post_type' => 'post', 'paged' => $paged);

	genesis_custom_loop($args);
}

/* This section removes the extra items like date posted, categories, etc
  We just want to see the content of the post
  */
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );

/*
 This section adds the classes each post (entry) to allow css to format them in alternating
 box colors
*/

$ou_count = 0;
$ou_carray = array('orange','blue','purple','green');
add_filter('genesis_attr_entry-content', 'ou_add_class',10,2);
function ou_add_class ($attributes, $context) {
    global $ou_count, $ou_carray;
	$ou_count += 1;
	$attributes['class'] = $attributes['class'] . " box " . $ou_carray[$ou_count%4];
	return $attributes;
}

genesis();
?>