Skip to content

Instantly share code, notes, and snippets.

@melissajclark
Last active February 22, 2016 03:25
Show Gist options
  • Save melissajclark/c7b61fa892387161f2af to your computer and use it in GitHub Desktop.
Save melissajclark/c7b61fa892387161f2af to your computer and use it in GitHub Desktop.
<?php
/**
* Controlling the class on an article in the WordPress loop
* Notes:
*
* <?php post_class(); ?> - this outputs the WordPress generated class for categories
* You can add classes by adding them inside this function. It will still output the WordPress classes
*
*/
?>
<?php if ( is_category('example') ) : ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('example-class'); ?>>
<?php elseif ( is_category('example-2') ) : ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('example-class-2'); ?>>
<?php else : // if it's not those categories then do this?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment