Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

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

Select an option

Save luisfelipe-dev/b52e010700d42b9d52268f12f48f0489 to your computer and use it in GitHub Desktop.
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 2,
'orderby' => 'rand',
);
$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="conteudo-rodape__item <?= $category ?>" style="background: url('<?= get_the_post_thumbnail_url(); ?>'); background-position: center center; background-size: cover;">
<div class="texto">
<div class="texto__cat">
<a href="javascript:void(0)">
<?= $category ?>
</a>
</div><!-- /texto__cat -->
<h3>
<?php the_title(); ?>
</h3>
</div><!-- /texto -->
</div><!-- /conteudo-rodape__item -->
<?php endwhile; ?>
<?php wp_reset_query(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment