Forums

[Plugin: Taxonomy Images BETA] Show image within single.php ? (11 posts)

  1. nicolinuxfr
    Member
    Posted 2 years ago #

    Hi !
    Thanks for the plugin, it was exactly what I was looking for !
    I'd like to show the image within single.php. I guess I should also be able to choose which taxonomy is involved...
    Can I do that with this plugin ? I tried to just add the <?php do_action( 'taxonomy_image_plugin_print_image_html', 'detail' ); ?> line somewhere, but it doesn’t work...
    Nicolinux

    http://wordpress.org/extend/plugins/taxonomy-images/

  2. Michael Fields
    Theme Wrangler
    Posted 2 years ago #

    Thanks for the plugin, it was exactly what I was looking for !

    No Problem! I really wanted it for my site too! Glad you like it.

    I'd like to show the image within single.php. I guess I should also be able to choose which taxonomy is involved...

    If you are using version 0.3 you should be able to use the get_image_html() method to display images in single views. It takes two arguments: the first is the size of the image and the second is the term_taxonomy_id of the image. Please bear in mind that this is different than the term_id.

    To return the image link:

    $my_var = $taxonomy_images_plugin->get_image_html( 'detail', $c->term_taxonomy_id );

    To print the image link:

    $taxonomy_images_plugin->print_image_html( 'detail', $c->term_taxonomy_id );

    Hope this helps,
    -Mike

  3. nicolinuxfr
    Member
    Posted 2 years ago #

    Thank you for your quick answer !

    I don't know where I can find the term_taxonomy_id. I tried with the slug of the taxonomy but as you said, it doesn't work... Could you tell me how to find it ?

    Thanks ! :-)

  4. Michael Fields
    Theme Wrangler
    Posted 2 years ago #

    You can try this loop:

    $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>';
    }

    If you want to use a different taxonomy, you can replace get_categories() with get_object_terms(). Something like this may work:

    $object_terms = wp_get_object_terms( $post->ID, 'fish' );

  5. umarglobal
    Member
    Posted 1 year ago #

    Did this work for you nicolinuxfr?

    Ive used the shortcode via the do_action() function. When using this in taxonomy.php template page the thumbs appear absolutely fine. But ive the same code in a page template file, menu.php and the thumbnails dont show up.

    Im using the following code to display the thumbnails

    <div class="taxonomy">
            	<ul>
    				<?php $args = array('taxonomy' => 'sections'); ?>
                    <?php $tax_menu_items = get_categories( $args );
                    foreach ( $tax_menu_items as $tax_menu_item ):?>
                    <li>
                    	<?php if (is_page()){?>
    						<?php do_action('taxonomy_image_plugin', 'fullsize'); ?>
                         <?php } else {?>
                    		<?php do_action('taxonomy_image_plugin_print_image_html', 'fullsize'); ?>
                         <?php } ?>
    
                        <h3><a href="<?php echo get_term_link($tax_menu_item, $tax_menu_item->taxonomy); ?>">
                            <?php echo $tax_menu_item->name; ?>
                        </a></h3>
                        <p> <?php echo $tax_menu_item->description; ?></p>
                    </li>
                    <?php endforeach; ?>
                </ul>
            </div>
  6. Michael Fields
    Theme Wrangler
    Posted 1 year ago #

    @umarglobal

    <?php do_action( 'taxonomy_image_plugin_print_image_html', 'detail' ); ?>

    is only meant to be used in taxonomy template. If I remember correctly, it is not meant to be used in single posts or pages. Try this instead:

    <?php do_shortcode( '[taxonomy_image_plugin]' ); ?>

    More information here:

    http://wordpress.org/extend/plugins/taxonomy-images/

  7. umarglobal
    Member
    Posted 1 year ago #

    Hi Micheal

    Thanks for the prompt response :)

    I have used the shortcode within the menu page in wp-admin as
    [taxonomy_image_plugin taxonomy="sections"]
    and everything works fantastically.

    However I want the tags to be displayed not within the post but in a particular position which i can on achieve by hard coding it in the template file menu.php where the menu page is using that template. Ive used the following code for this and nothing comes up
    <?php do_shortcode( '[taxonomy_image_plugin taxonomy="sections"]'); ?>

    Is this a bug or am i doing something wrong. BTW fantastic plugin

    Thanks

    Umar

  8. Michael Fields
    Theme Wrangler
    Posted 1 year ago #

    Thanks! Does the menu page have any sections associated with it?

  9. umarglobal
    Member
    Posted 1 year ago #

    No not at all its just a standard wordpress page.

    Confusing thing is that it appears fine when using the short code in wp-admin but when hardcoding it in the template file "menu.php" nothing shows

  10. Michael Fields
    Theme Wrangler
    Posted 1 year ago #

    Maybe a very slight modification will do the trick:

    <?php print do_shortcode( '[taxonomy_image_plugin]'); ?>

    :)

  11. umarglobal
    Member
    Posted 1 year ago #

    That worked just fine :)

    Your so helpful.. Thank you. Great plugin

Topic Closed

This topic has been closed to new replies.

About this Topic