Skip to content

Instantly share code, notes, and snippets.

@flowck
Created July 31, 2018 13:20
Show Gist options
  • Save flowck/6381b16c89ba36c2cdaa1bffd45a0cba to your computer and use it in GitHub Desktop.
Save flowck/6381b16c89ba36c2cdaa1bffd45a0cba to your computer and use it in GitHub Desktop.
<?php
$args = array(
"posts_per_page" => 8
);
$Eventos = new WP_Query($args);
if($Eventos->have_posts()){
while($Eventos->have_posts()){
$Eventos->the_post();
// Obtem a imagem de destaque
$img = wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()));
// Se não houver imagem de destaque, então apresenta uma imagem padrão
if($img == ""){
$img = get_template_directory_uri() . "/img/default.png";
}
?>
<a class="card" href="<?php the_permalink(); ?>">
<!-- Imagem de destaque como background -->
<figure style="background-image: url(<?php echo $img;?>);">
</figure>
<div class="info">
<div class="categoria">
<!-- Mostra a primeira categoria, caso um post tiver multiplas categorias -->
<?php $cat = get_the_category()[0]; print_r($cat->cat_name); ?>
</div>
<div class="space single"></div>
<div class="event-title">
<h2 title="<?php the_title(); ?>">
<?php
// Limitar o titulo caso exceder 80 carateres
if (strlen(get_the_title()) > 80) {
echo substr(get_the_title(), 0,80) . ' [...]';
} else {
echo the_title();
}
?>
</h2>
</div>
<div class="space"></div>
<div class="description">
<?php echo substr(get_the_excerpt(), 0, 100); ?> [...]
</div>
<div class="space"></div>
<div class="space"></div>
<div class="time">
<span class="icon-calendar-o"></span>
<?php
$dataInicio = date_create(get_field('data_de_inicio'));
$dataFim = date_create(get_field('data_do_fim'));
echo date_format($dataInicio, 'd/m/Y') . ' – ' . date_format($dataFim, 'd/m/Y');
?>
</div>
</div>
</a>
<?php }} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment