WordPress.org

Ready to get started?Download WordPress

Forums

Adding Custom Taxonomy Images to Custom Post Type (7 posts)

  1. morality28
    Member
    Posted 2 years ago #

    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!

  2. Michael Fields
    Themer
    Posted 2 years ago #

    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',
        ) );
  3. morality28
    Member
    Posted 2 years ago #

    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:
    http://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!

  4. Michael Fields
    Themer
    Posted 2 years ago #

    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>',
    ) );
    ?>
  5. morality28
    Member
    Posted 2 years ago #

    Doh.....perfect thanks!

    Thanks for the help

  6. Michael Fields
    Themer
    Posted 2 years ago #

    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

  7. morality28
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic