• I have tried installing the taxonomy images plugin, and other taxonomy manager plugins, but I’m not good with php and coding and I can’t seem to figure out how to get what I want.

    I have a custom post type archive page template as my static homepage. I have a single custom taxonomy ‘country’. I have created categories for different countries, and attached flags to them as an image meta-data. Similar to how there are icons for post type (like blog, video, image) I would like to display these icons only for the ‘country’ taxonomy in the upper left corner of each post (like those themes that display the post type icon sort of upper left, outside the post margin).

    I would love if someone could suggest the simplest way to accomplish this, whether I can do it with the Taxonomy Images plugin and what the code might look like (and do I add this code to my functions.php or to my custom-post-type-archive.php?).

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Please see the section named List term images associated with a post object on the plugin page. This explains the function that you need to use and how to customize it.

    Placing the following in the loop of your custom post_type archive template should get you started:

    print apply_filters( 'taxonomy-images-list-the-terms', '', array(
        'image_size'   => 'detail',
        'taxonomy'     => 'country',
        ) );
    Thread Starter morality28

    (@morality28)

    Okay – I have added in the code to my template:

    if( $wp_query->have_posts() ) : while( $wp_query->have_posts() ) : $wp_query->the_post();
    $catalyst_loop_count++;
    $more = 0; ?>
    
    <div <?php post_class(); ?>>
    
    print apply_filters( 'taxonomy-images-list-the-terms', '', array(
        'image_size'   => 'detail',
        'taxonomy'     => 'eligibility',
        'after'        => '</div>',
        'after_image'  => '</span>',
        'before'       => '<div class="icon">',
        'before_image' => '<span>',						) );

    And what I see on the page is this:
    https://i658.photobucket.com/albums/uu310/morality28/codesample.jpg

    Like I said I’m very new to this so I’m not sure what I’m doing wrong?
    Thanks for your help!

    No worries… you need to put the code in php tags like this:

    <?php
    print apply_filters( 'taxonomy-images-list-the-terms', '', array(
        'image_size'   => 'detail',
        'taxonomy'     => 'eligibility',
        'after'        => '</div>',
        'after_image'  => '</span>',
        'before'       => '<div class="icon">',
        'before_image' => '<span>',
    ) );
    ?>
    Thread Starter morality28

    (@morality28)

    Doh…..perfect thanks!

    Thanks for the help

    Glad it worked. This plugin should be adding no extra css to your template files. I’m not sure where the border is coming from, but some themes do add borders to images in certain places. You could try something like:

    .icon img {
        border-width:0 !important;
    }

    but it would be better to fix this with a more specific selector:

    #container .icon img {
        border-width:0;
    }

    Best,
    -Mike

    Thread Starter morality28

    (@morality28)

    Thanks – I found the culprit elsewhere in my stylesheet (I was styling all img tags for my custom post type)

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding Custom Taxonomy Images to Custom Post Type’ is closed to new replies.