• I’m currently trying to list all child categories on a parent level category, with a depth of 1, and the same as you go down a level, until you get to the final sub category in the chain.

    I have this code working, but I desperately need to get the images I have set using your (awesome!) plugin. I’m pretty new to php so am struggling some what – can anyone give any help in how to alter this to achieve my desired result?

    <?php global $ancestor; // Declare global ancestor variable ?>
    <?php foreach ($categories as $cat) {
    	if ($cat->cat_ID != 1) { // If category is not uncategorized ...
    	if (cat_is_ancestor_of($ancestor, intval($cat->cat_ID)) == false) { // .. and if the previous category in the loop wasn't the ancestor of this one ... ?>
    		<h2><a href="<?php echo get_category_link($cat->cat_ID); ?>"><?php echo ($cat->cat_name); ?></a></h2>
    		<?php echo ( category_description($cat->cat_ID) );  ?>
    		<?php print apply_filters( 'taxonomy-images-queried-term-image', '' ); ?>
    		<?php
    		$ancestor = intval($cat->cat_ID); }; // make this category the new ancestor
    		};
    	};
    ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Fields

    (@mfields)

    What function are you using to define the categories variable? If you are using on of the supported filters from the Taxonomy Images plugin, you can use $cat->image_id.

    Maybe:

    $categories = apply_filters( 'taxonomy-images-get-terms', '' );

    I notice that you are using <?php print apply_filters( 'taxonomy-images-queried-term-image', '' ); ?>. This should not be in loops … it was designed to be used only in term archive templates like category.php and tags.php.

    Thread Starter brettsmason

    (@brettsmason)

    Hi Michael

    Thanks for getting back to me. I actually pasted the wrong code, sorry! What I posted wasn’t outputting the category details like I thought, it was: `<?php
    $cat = get_query_var(‘cat’);

    $categories=get_categories(‘depth=1&child_of=’.$cat);
    foreach($categories as $category) {
    echo $category->name;
    echo $category->description;
    }
    ?>`

    Sorry for my stupidity, but how would I incorporate your code into this? I have tried a few things without success.

    Plugin Contributor Michael Fields

    (@mfields)

    Maybe something like this might work (untested):

    $categories = apply_filters( 'taxonomy-images-get-terms', '', array(
    	'term_args' => array(
    		'child_of' => $cat,
    		'depth'    => 1
    	)
    ) );
    Thread Starter brettsmason

    (@brettsmason)

    Thanks Michael

    With a bit of fiddling I have managed to get images outputting. However I don’t think I’m doing it right as it’s listing all of the categories. The code I have is:

    <?php
    $cat = get_query_var('cat');
    $categories = apply_filters( 'taxonomy-images-get-terms', '', array(
    	'term_args' => array(
    		'child_of' => $cat,
    		'depth'    => 1
    	)
    ) );
    foreach($categories as $category) {
    echo $category->name;
    echo $category->description;
    echo wp_get_attachment_image( $category->image_id, 'detail' );
    }
    ?>

    Still learning php so sorry if there’s something glaringly obvious!

    Thread Starter brettsmason

    (@brettsmason)

    I’m still having no luck with this, I cant work out what I’m doing wrong. Any suggestions welcome!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Trouble incorporating taxonomy images into existing code’ is closed to new replies.