Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save luisfelipe-dev/beb5d3dc8d833b8082a53bc0ba7fdac5 to your computer and use it in GitHub Desktop.

Select an option

Save luisfelipe-dev/beb5d3dc8d833b8082a53bc0ba7fdac5 to your computer and use it in GitHub Desktop.
Loop para adicionar o nome da categoria na classe.
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 100,
'orderby' => 'date',
'order' => 'DESC'
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ):
$loop->the_post();
$postcat = get_the_category();
if ( ! empty( $postcat ) ) {
$category = $postcat[0]->slug ;
$category_name = $postcat[0]->name ;
}
?>
<div class="<?= $category ?>">
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment