Is there a way to keep my "category name" in the loop, but display it only once for the first post? And not all the posts. I know i can keep it out of the loop, but just wondering if this is possible.
<?php
$args = array(
'post_type' => 'post',
'orderby' => 'date',
'order' => 'ASC',
'cat' => 19
);
$catg = new WP_Query($args);
?>
<?php if($catg->have_posts()) : ?>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 lock">
<?php while($catg->have_posts()) : $catg->the_post() ?>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 lock">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<?php
$category = get_the_category();
?>
<h2 style="text-transform: uppercase;"><?php echo $category[1]->cat_name; ?></h2>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 lock">
<a href="<?php echo get_permalink( $post->ID ); ?>" class="topico1-link-c">
<div class="topico3-col2-c cursos-margem-direita col-xs-12 col-sm-12 col-md-12 col-lg-12" style="padding-left: 0px;">
<div class="topico1-img col-xs-12 col-sm-12 col-md-12 col-lg-12 lock">
<img src="<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>">
<div class="imagem-pelicula"></div>
</div>
<div class="topico1-title col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h3 class="h3-low-c"><?php echo get_the_title(); ?></h3>
</div>
</div>
</a>
</div>
</div>
<?php endwhile ?>
<?php endif ?>
</div>
Also is there a way to get the child category name? When i try this:
<?php
$category = get_the_category();
?>
<h2 style="text-transform: uppercase;"><?php echo
$category[1]->cat_name; ?></h2>
I get the right information, but if for some reason the parent name comes alphabetically in second, i get the parent name and not the child.
Thank you in advance.
Kind regards!