WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How To Link Product Thumbnails To Custom Post Type? (3 posts)

  1. luisbonie
    Member
    Posted 1 year ago #

    Thank you for your help... I hope i explain this right someway or another... My goal is to have the woocommerce product thumbnails link to a custom post type like a single product...

    3.5 version does not allow the custom link for images so I used the "WP Gallery Custom Links" to assign a link to each image, but it only works for post/page gallery when the shortcode is used as it should... How or Can I edit the product-thumbnail.php to use the custom link field...

    Here is a screen shot...

    Here is the code for mytheme/woocommerce/single-product/product-thumbnail.php

    <?php
    global $post, $woocommerce;
    ?>
    <div class="thumbnails"><?php
    	$attachments = get_posts( array(
    		'post_type' 	=> 'attachment',
    		'numberposts' 	=> -1,
    		'post_status' 	=> null,
    		'post_parent' 	=> $post->ID,
    		'post__not_in'	=> array( get_post_thumbnail_id() ),
    		'post_mime_type'=> 'image',
    		'orderby'		=> 'menu_order',
    		'order'			=> 'ASC'
    	) );
    	if ($attachments) {
    
    		$loop = 0;
    		$columns = apply_filters( 'woocommerce_product_thumbnails_columns', 3 );
    
    		foreach ( $attachments as $key => $attachment ) {
    
    			if ( get_post_meta( $attachment->ID, '_woocommerce_exclude_image', true ) == 1 )
    				continue;
    
    			$classes = array( 'zoom' );
    
    			if ( $loop == 0 || $loop % $columns == 0 )
    				$classes[] = 'first';
    
    			if ( ( $loop + 1 ) % $columns == 0 )
    				$classes[] = 'last';
    
    			printf( '<a href="%s" title="%s" rel="thumbnails" class="%s">%s</a>', wp_get_attachment_url( $attachment->ID ), esc_attr( $attachment->post_title ), implode(' ', $classes), wp_get_attachment_image( $attachment->ID, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ) ) );
    
    			$loop++;
    
    		}
    	}
    ?></div>

    Your thoughts are very much appreciated... THANKS!!!

  2. luisbonie
    Member
    Posted 1 year ago #

    This is the field that I would like the thumbnail to use "attachments-262-gallery_link_url" but am not sure how to write it in the "wp_get_attachment_url( $attachment->ID )"

    am I going about this the right way?

  3. luisbonie
    Member
    Posted 1 year ago #

    Will close this... Sir Ben Blanco has made it happen for me... thanks anyway :)

Topic Closed

This topic has been closed to new replies.

About this Topic