I have parent category, Game (cat ID 42), and some child categories in it: Acrade, Causaul. After I using the loop to get the title of the post, I want to have a child category name. But my code is not working:
<?php
$args = array(
'cat' => 42,
'posts_per_page' => 12,
'post__in' => get_option( 'sticky_posts' ),
);
// The Query
$the_query = new WP_Query( $args );
$categories = get_the_category($post->ID);
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
?>
<?php
/* if post has a thumbnail */
if ( ( function_exists('has_post_thumbnail') ) && ( has_post_thumbnail() ) ) { ?>
<li>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_post_thumbnail('app_icon', array('title' => get_the_title())); ?></a>
<p class="ptit">
<a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a>
</p>
<span class="cate"><?php echo $categories ?></span>
</li>
<?php
} /* end if post has a thumbnail */
endwhile;
// Reset Post Data
wp_reset_postdata();
?>