Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capture/hide the "warning" generated by taxonomy-images-get-the-terms on a not-image-enabled-taxonomy. #14

Open
berteh opened this issue Apr 25, 2013 · 0 comments

Comments

@berteh
Copy link

berteh commented Apr 25, 2013

how to capture/hide the "warning" generated by this plugin when taxonomy-images-get-the-terms is called on a taxonomy for which the taxonomy-images function is not activated? or add a test function to your code "taxonomy-images-is-active-for-taxonomy"? As it is a warning and not an error I cannot try/catch it.

I want to automate the display of images for all terms of all taxonomies that have an image associated. Unfortunately your plugin raise a warning for taxonomies for which taxonomy-images has not be activated.

For info / other users my code for displaying all terms images is below, terms with no images get displayed as text links (to be put in your template functions.php).

function custom_taxonomies_terms_links_images() {

$id = get_the_ID();
$post_type = get_post_type($id);
$taxonomies = get_object_taxonomies($post_type);
$out_images = $out_texts = array();
foreach ($taxonomies as $taxonomy) {
    //if ($taxonomy == 'post_format') //internal WP3.1+ taxonomy, skip.
    //  continue;
    //next filter shows notice on blog if images not activated for taxonomy
    $terms = apply_filters( 'taxonomy-images-get-the-terms', '', array(
       'taxonomy'     => $taxonomy,
       'post_id' => $id
    ) );
    // if the above rises a warning, then images are not activated for this taxonomy, then populate terms with:
    //    $terms = get_the_terms( $id, $taxonomy );        

    if ( !empty( $terms ) ) {
        foreach ( $terms as $term )
            if (!empty($term->image_id)) {
                $out_images[] = '<li class="taxonomy-image"><a href="' . esc_url( get_term_link( $term, $taxonomy ) ) . '" title="'.$term->name.' ('.$taxonomy.')">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</li>';
            }
            else
                $out_texts[] = '<a href="' .get_term_link($term->slug, $taxonomy) .'">'.$term->name.'</a>';
    }
}
if ($out_texts)
    $out_images[] = '<li class="taxonomy-text">'.join( ', ', $out_texts).'</li>';  

return '<ul class="taxonomy-images-the-terms">'.join( '', $out_images).'</ul>';

}

simply call it with <?php echo custom_taxonomies_terms_links_images(); ?> wherever the loop is displaying the categories of a post, for instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant