kahi – Thanks for the feedback – I will look into the compatibility issue in the next couple of days. I have absolutely no problem with making the settings var public. I used the $wp_query in the action becuse it was the only way (that I could find) to get the term_taxonomy_id on all suported views. If you know a better way, I would love to know!
Thread Starter
kahi
(@kahi)
@mfields, I have absolutely no problem with reading term-id from $wp_query – I wanted to show (and with help of get_option() I did) images inside own cycle of categories (got by get_categories() which does not modify $wp_query), so I had to seek for other way than do_action().
Basically, instead of:
<?php
$cat_to_att = get_option('taxonomy_image_plugin');
$cats = get_categories(array(...));
foreach ($cats as $c) { ?>
<a href="<?php echo get_category_link($c->term_id) ?>">
<?php if ($cat_to_att[$g->term_id]) echo wp_get_attachment_image($cat_to_att[$g->term_id], 'thumbnail'); ?>
</a>
<?php
} ?>
There would be nice possibility of:
<?php
$cats = get_categories(array(...));
foreach ($cats as $c) { ?>
<a href="<?php echo get_category_link($c->term_id) ?>">
<?php if (YourPlugin::CatToAtt($c->term_id)) echo wp_get_attachment_image(YourPlugin::CatToAtt($c->term_id), 'thumbnail'); ?>
</a>
<?php
} ?>
Sorry for the verbose explanation, it probably wasn’t necessary.
kahi,
I was able to find a work around to a couple of bugs that I discovered in the Reveal IDs for WP Admin plugin. Thanks for the tip! It was a super easy fix.
Please note that this plugin stores an array that use the $term->term_taxonomy_id as the key and the $post->ID of the attachment as it’s value. Although $term->term_id will work in some cases, it can return a false positive where multiple taxonomies share the same name.
I added a argument to get_image_html() and print_image_html() which will allow you to pass the term_taxonomy_id to specify which image you would like returned. You second example would look something like this:
$cats = get_categories();
foreach ( $cats as $c ) {
$url = get_category_link( $c->term_id );
$img = $taxonomy_images_plugin->get_image_html( 'medium', $c->term_taxonomy_id );
if( !empty( $img ) )
print '<a href="' . $url . '">' . $img . '</a>';
}
Before you upgrade to 0.3, MAKE SURE TO DELETE LINE 75:
<?php do_action( 'taxonomy_image_plugin_print_image_html', 'detail' ); ?>
Thread Starter
kahi
(@kahi)
@mfields, thank you twice. 🙂
No problem! Thanks for informing me of the incompatibility!
This doesn’t work for me:
$cats = get_categories();
foreach ( $cats as $c ) {
$url = get_category_link( $c->term_id );
$img = $taxonomy_images_plugin->get_image_html( 'detail', $c->term_taxonomy_id );
if( !empty( $img ) )
print '<a href="' . $url . '">' . $img . '</a>';
}
Error returned:
Fatal error: Call to a member function get_image_html() on a non-object in /wp-content/themes/default/header.php on line 106
Not sure what’s going on here . . .
Try putting this line before the code you posted above:
global $taxonomy_images_plugin;