• Resolved SAFEER N

    (@safeerpangode)


    i’m new in wp.
    i’m using Category template hierarchy (http://wordpress.org/extend/plugins/category-template-hierarchy/) for using parent-category.php

    my parent-category.php

    <section id="list">
        <?php display_sub_categories(); ?>
    </section>

    my function.php

    function display_sub_categories() {
    	$image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '' );
    	$current_cat = get_query_var('cat');
    	$args = array('child_of'=>$current_cat);
    	$categories = get_categories($args);
    	if (!empty($categories)) {
    		echo '
    <ul>';
    		foreach ($categories as $category) {
    			echo '
    <li><a>slug.'">'. $category->name .'</a><img src="'.$image_url.'" /></li>
    ';
    		}
    		echo '</ul>
    ';
    	} else {
    		// fallback for when no subcategories are available
    	}
    }

    but this line ‘ $image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '' ); ‘ showing current category image. how can i change this line to get child category image.

    please help me, i’m not well in php,wordpress,english.
    thanks in advance.

    http://wordpress.org/extend/plugins/taxonomy-images/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter SAFEER N

    (@safeerpangode)

    function display_sub_categories() {
    	$cat_id = get_query_var('cat');
    	$catlist = get_categories('hide_empty=0&child_of=' . $cat_id);
    	echo "<ul>";
    	foreach($catlist as $categories_item)
    	{
    		echo '<li>';
    		echo '<h3><a href="' . get_category_link( $categories_item->term_id ) . '" title="' . sprintf( __( "%s" ), $categories_item->name ) . '" ' . '>' . $categories_item->name.'</a> </h3> ';
    	    $terms = apply_filters( 'taxonomy-images-get-terms', '' );
    	    if ( ! empty( $terms ) ) {
    	      foreach( (array) $terms as $term ) {
    		        if($term->term_id == $categories_item->term_id) {
    		           print '<a class="thumb" href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'full' );
    		           echo '</a>';
    		       	 }
    	    	}
        		echo '<p>'. $categories_item->description; echo '</p></li>';
    		}
    	}
    	echo '</ul>';
    }

    problem solved with this.

    I thought maybe you can help me here. I am trying to get the child categories also but I am not having any luck. I tried your code above without any luck. Here is the query I am using, this is returning the posts exactly how I need them

    $allcats = get_categories('child_of='.get_query_var('cat'));
        foreach ($allcats as $cat) :
        $args = array(
        'posts_per_page' => 3, // max number of post per category
    
        'category__in' => array($cat->term_id)
        );
    
        $customInCatQuery = new WP_Query($args); 
    
        if ($customInCatQuery->have_posts()) :
        echo '<div class="menupageContent">';
        //THIS IS WHERE I NEED THE IMAGES TO SHOW
        print apply_filters( 'taxonomy-images-queried-term-image', 'menu' );
        echo '<h3>'.$cat->name.'</h3>';
        echo '<ul>';
        while ($customInCatQuery->have_posts()) : $customInCatQuery->the_post(); ?>
    
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    
    <?php
    endwhile;
    echo '</ul></div><!--end menupageContent-->';

    My problem now is that nothing I do will return the images. I have three images posted to three categories and each one has been assigned to the same parent category. I can’t get the images or if I do, I get all of them 9 times when I should only get 3. Can you help?

    Same problem here – using custom tax – this shows child terms but with no images…

    HELP PLEASE!
    ta:

    $current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    
    	$args = array(
    								'taxonomy'     => $current_term->taxonomy,
    								'child_of' 	   => $current_term->term_id,
    								'hide_empty' => false,
    								'title_li'     => '',
    									'term_args'    => array(
    									'orderby'      => 'id',
    									'order'        => 'ASC',
    									'hierarchical' => true,
    									'depth'  => 3,
    									),
    
    								);
    
    	$cats = wp_list_categories ( $args );
    
    		foreach ($cats as $cat)
    		{
    			echo '<li><a href="' . get_category_link($cat) . '" title="'. $cat->name .'">' ;
    			$terms = apply_filters( 'taxonomy-images-get-terms', '' );
    			if ( ! empty( $terms ) ) {
    			foreach( (array) $terms as $term ) {
    					if($term->term_id == $cat->term_id) {
    					  echo wp_get_attachment_image( $term->image_id, 'detail' );
    					}
    			}
    			}
    			echo $cat->name ;
    			echo '</a></li>';
    		}

    OK, Sorted – used:

    ‘parent’ => $current_term->term_id,

    instead of:

    ‘child_of’ => $current_term->term_id,

    Worked for me as well, thank you.

    elbego, looks like I’m two weeks behind you in attempting same thing, your code looks really close to what I’m doing, I’d appreciate some help:

    Here’s what I’ve got working –

    $term_slug = get_query_var( 'term' );
    $taxonomyName = get_query_var( 'taxonomy' );
    $current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
    // begin check if no children - to not show 'no category' message
    $termchildren = get_term_children( $current_term->term_id, $taxonomyName);
    if($termchildren && ( !is_wp_error( $termchildren ))) {
    // end check
     // whole section with $args_list and wp_list_categories($args_list) here;
    }
    $args_list = array(
        'taxonomy' => 'destinations', // or use $taxonomyName for all taxonomies
        'show_count' => true,
        'hierarchical' => true,
        'child_of' => $current_term->term_id,
        'hide_empty' => '0',
        'title_li' => '',
        'echo' => '0',
    );
    
    echo wp_list_categories($args_list);

    This code is fine and dandy and displays a couple of child terms as an unordered list of links when on a Parent taxonomy archive.

    I’ve adjusted where it seemed sensible to reflect elbego’s code:

    $term_slug = get_query_var( 'term' );
    $taxonomyName = get_query_var( 'taxonomy' );
    $current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
    
    	$args = array(
        'taxonomy' => 'destinations', // or use $taxonomyName for all taxonomies
        'show_count' => true,
        'hierarchical' => true,
        'parent' => $current_term->term_id,
        'hide_empty' => '0',
        'title_li' => '',
        'echo' => '0',
    );
    $cats = wp_list_categories ( $args );
    
    	foreach ($cats as $cat)
    		{
    			echo '<li><a href="' . get_category_link($cat) . '" title="'. $cat->name .'">' ;
    			$terms = apply_filters( 'taxonomy-images-get-terms', '' );
    			if ( ! empty( $terms ) ) {
    			foreach( (array) $terms as $term ) {
    					if($term->term_id == $cat->term_id) {
    					  echo wp_get_attachment_image( $term->image_id, '' );
    					}
    			}
    			}
    			echo $cat->name ;
    			echo '</a></li>';
    		}

    I’ve made the ‘child_of’ switch to ‘parent’ in the Array, and switched the code from the ‘echo wp_list_categories($args_list);’ point.

    Unfortunately, I get a ‘Warning: Invalid argument supplied for foreach()‘ message.

    Seems to be as soon as it hits here: ‘foreach ($cats as $cat)’ there’s a problem.

    Could anyone lend a very frustrated fella a hand in getting a few images to ‘show’, it really shouldn’t be so tough to do ; )

    This was my code… firstly note that the array for the taxonomy images should use term_args:

    'taxonomy'     => $current_term->taxonomy,
    	'hide_empty' => false,
    	'title_li'     => '',
    		'term_args'    => array(                        // passes info to images
    		'parent' 	   => $current_term->term_id,      // outputs children of current term
    		'hide_empty'   => 0,						  // shows all
    		'orderby'      => 'name',
    		'order'        => 'ASC',
    		'hierarchical' => true,
    	 ),

    Do you have any idea how to paginate this setup? I have my code set up so that I have one main category called menu, under that, I have multiple child categories like breakfast, lunch, dinner, wine list each set up to have the MENU parent category. I have been able to get only 3 of the child categories to show but I have not been able to get the pagination working to show the wine list or any other menu item.

    Here is my code

    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $allcats = get_categories(array('child_of' => get_query_var('cat'), 'number' => 3,'order'=> 'asc', 'paged' => $paged)); 
    
     foreach ($allcats as $cat) :
    $args = array(
     'category__in' => array($cat->term_id),
     'paged' => $paged,
     'posts_per_page' => 5
    );
    
     query_posts($args); 
    
    if (have_posts()) :
    echo '<div class="menupageContent">';
    
            $terms = apply_filters( 'taxonomy-images-get-terms', '' );
            if ( ! empty( $terms ) ) {
            foreach( (array) $terms as $term ) {
                    if($term->term_id == $cat->term_id) {
                      echo wp_get_attachment_image( $term->image_id, 'menu' );
                    }
            }
            }
    
    echo '<h3>'.$cat->name.'</h3>';
    echo '<ul>';
    while (have_posts()) : the_post(); ?>
    
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    
     <?php
     endwhile;
     echo '</ul></div><!--end menupageContent-->'; 
    
     ?>
    
     <?php else :
     echo 'No post published in:'.$cat->name;
     endif;
     wp_reset_query();
     endforeach; 
    
     ?>

    Hi Elbego, can you help me out with this

    <img src="<?php foreach((get_the_category()) as $category) $term_id = $category->cat_ID; $image = get_option( 'taxonomy_image_' . $term_id ); echo $image; ?>" alt="<?php $category = get_the_category(); echo $category[0]->cat_name; ?>" class="catimg" />

    I want to get the subcategory image but using this code i am getting only category image. Not an expert just on a learning phase if you can edit my code it will be awesome.

    Help would be appreciated.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Plugin: Taxonomy Images] get child category image’ is closed to new replies.