Get link to child category
-
Hi there.
I’m building this wordpress theme where I have a page that lists all categories of a parent cat (in this case called “exhibitions”). I have no problem getting the latest post in each child category and listing it accordingly (with a bunch of sniffing around these forums, I must admit).However, I’d also like to link those “last posts” to their respective child category to list all the posts in the chosen cat.
The code I’m using is as follows:
<?php $taxonomy = 'category'; $param_type = 'category__in'; $cat_id = get_cat_ID('exhibitions'); $term_args=array( 'orderby' => 'name', 'order' => 'ASC', 'child_of' => $cat_id ); $terms = get_terms($taxonomy,$term_args); if ($terms) { foreach( $terms as $term ) { $args=array( "$param_type" => array($term->term_id), 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <li><?php echo '<a href="CHILD CATEGORY LINK HERE"/>' ?><?php the_post_thumbnail( array(410,279) ); ?></a></li> <?php endwhile; } } } wp_reset_query(); ?>
Any help would be madly appreciated.
Thanks!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Get link to child category’ is closed to new replies.