child taxonomy and it's template
-
hi there, i have a taxonomy called “brand” with child taxonomies of cities like “koeln” linked to a custom post type called “distributors” where i can add shops with name, address and so on.
since i create a link to the list of cities of each brand on another custom post type, called “marken”, i (think i have to) pass a variable with GET to check on which page of “marken” i am.
that works pretty good, and by clicking on the main link, the list of cities for the dependend brand is listed. now my problem:
by clicking on a city name, each entry of “distributors” linked to it shall show custom fields like the name, address, etc.
this works ONLY if i save a new file for the child taxonomy, as example: “taxonomy-{taxname}-{name-of-child-tax}.php” or in detail “taxonomy-brand-koeln-welder.php”.
the problem is the huge amount of child taxonomies and that i have to edit all of them if i want to make a change to the template…
i tried it with conditional tags, like asking if it’s a parent page and so on… here you can see the actual example. and sorry for my messy code – i’m not working that long with wordpress and php:
<?php get_header(); ?> <?php $queried_object = get_queried_object(); $current_id = $queried_object->term_id; $current_slug = $queried_object->slug; ?> <?php if($term->parent > 0) { // here begins the part of the child taxonomy output ?> <?php $args=array( 'name' => $current_slug, 'post_type' => 'marken', 'post_status' => 'publish', 'showposts' => 1, 'caller_get_posts'=> 1 ); $my_posts = get_posts($args); if( $my_posts ) { $my_id = $my_posts[0]->ID; echo '<div id="single-brand">'; echo '<div class="headline"><h2 class="line"><span class="white-bg"><img src="'.get_field('logo', $my_id).'" alt="'.get_the_title($my_id).'" ></span></h2></div></div>'; } wp_reset_query(); $args = array( 'post_type' => 'distributors', 'tax_query' => array( array( 'taxonomy' => 'brand', ) ) ); ?> <?php $query = new WP_Query( $args ); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if( has_term( $current_slug, 'brand' ) ) {?> <div class="distributor"> <table><tr><td> <img src="<?php bloginfo('template_directory'); ?>/images/icon-pin-big.png" alt="<?php the_title(); ?>" /> </td> <td> <h2><?php the_title(); ?></h2> <p><?php the_field('distributor_address'); ?></p> <p>Tel. <?php the_field('distributor_phone'); ?><br> Fax <?php the_field('distributor_fax'); ?></p> </td></tr></table> <a href="http://<?php the_field('distributor_web'); ?>" class="button" target="_blank">Shopseite besuchen</a> </div> <?php } endwhile; endif; ?> <?php wp_reset_query(); ?> <a href="<?php bloginfo('url'); ?>/index.php/brand/<?php echo $current_slug; ?>/" >Zurück zur Händlerliste</a> <?php } else // here begins the list of the cities { $args=array( 'name' => $current_slug, 'post_type' => 'marken', 'post_status' => 'publish', 'showposts' => 1, 'caller_get_posts'=> 1 ); $my_posts = get_posts($args); if( $my_posts ) { $my_id = $my_posts[0]->ID; echo '<div id="single-brand">'; echo '<div class="headline"><h2 class="line"><span class="white-bg"><img src="'.get_field('logo', $my_id).'" alt="'.get_the_title($my_id).'" ></span></h2></div></div>'; } wp_reset_query(); $args=array( 'post_type' => 'distributors', 'post_status' => 'publish', 'showposts' => 1, 'tax_query' => array( array( 'taxonomy' => 'brand', 'field' => 'slug', 'terms' => $current_slug ) ) ); $my_posts = get_posts($args); if( $my_posts ) { $term_id = $current_id; $taxonomyName = "brand"; $termchildren = get_term_children( $term_id, $taxonomyName ); echo '<h3>Händlerliste</h3>'; echo '<ul>'; foreach ($termchildren as $child) { $term = get_term_by( 'id', $child, $taxonomyName ); $term_link = get_term_link( $term, $taxonomyName ); echo '<li><a href="'.$term_link.'?marke='.$current_slug.'">'.$term->name.'</a></li>'; } echo '</ul>'; }} ?> <?php get_footer(); ?>the conditional “if($term->parent > 0)” works for the list of cities, but the output of child taxonomy is not shown. is there anything wrong with all my queries? as i said: when i make a separate file for the child taxonomy with the first code part, everything works… i really despair of it 🙁
thx in advance
The topic ‘child taxonomy and it's template’ is closed to new replies.