如何使Woocommerce产品缩略图可点击(导航)?

时间:2018-10-01 18:23:07

标签: php product thumbnails

我有一个网站GforGadget。我正在使用woocommerce主题。我的产品名称是可单击的,但不是我的产品图像。单击产品缩略图时,我需要导航到相应的产品页面。如何实现。

有两个相关的php文件 1.Product.php

<?php
/**
 * Single Product Image
 *
 * @author 		WooThemes
 * @package 	WooCommerce/Templates
 * @version     3.3.2
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

global $post, $woocommerce, $product;
$has_thumbs = false;
ob_start();
?>

<div class="image-table-wrapper">

    <div class="row">

		<div class="image-wrapper<?php if(plsh_gs('zoom_catalog_images_on_hover') == 'on') { echo ' zoom-enabled'; } ?>">

            <?php woocommerce_show_product_sale_flash(); ?>

            <?php if ( has_post_thumbnail() ) : ?>

                <?php
                $unique_slider_id = uniqid();
                $thumb_ids = array();
                ?>
                <div class="image-slides cycle-slideshow images" id="single-product-slider"
                    data-cycle-swipe="true"
                    data-cycle-swipe-fx="scrollHorz"
                    data-index="1"
                    data-cycle-log="false"
                    data-cycle-fx="scrollHorz"
                    data-cycle-timeout="0"
                    data-cycle-speed="200"
                    data-cycle-pager="#<?php echo esc_attr($unique_slider_id); ?>"
                    data-cycle-auto-height="1:1"
                    data-cycle-pager-active-class="active"
                    data-cycle-pager-template=""
                    data-cycle-prev=".<?php echo esc_attr($unique_slider_id); ?>_prev"
                    data-cycle-next=".<?php echo esc_attr($unique_slider_id); ?>_next"
                    data-cycle-slides=".image" 
                >

                    <div class="image active main-slide" style="background-image: url(<?php echo plsh_get_thumbnail('plsh_product_single', true); ?>);"></div>
                
                    <?php
                        global $product;
                        $gallery = $product->get_gallery_image_ids();

                        if($product->get_type() == 'variable')
                        {
							$variations = plsh_get_available_variation_ids();
							
                            foreach($variations as $variant)
                            {
                                if(has_post_thumbnail( $variant ))
                                {
                                    $id = get_post_thumbnail_id($variant);
                                    $img = wp_get_attachment_image_src( $id, 'plsh_product_single' );

                                    if(plsh_gs('show_variant_thumbs') != 'off')
                                    {
                                        echo '<div class="image" id="image-' . $variant . '" style="background-image: url(' . $img[0] . ');"></div>';
                                    }

                                    $thumb_ids[] = array('id' => $id, 'type' => 'variant', 'variation_id' => $variant, 'img' => $img[0]);
                                }  
                            }
                        }

                        if(!empty($gallery))
                        {
                            $loop = 0;
                            foreach ( $gallery as $value ) 
                            {
                                $img = wp_get_attachment_image_src( $value, 'plsh_product_single' );
                                echo '<div class="image" style="background-image: url(' . $img[0] . ');"></div>';
                                $thumb_ids[] = array('id' => $value, 'type' => 'gallery', 'img' => $img[0]);
                            }
                        }
                    ?>
                </div>

                <?php global $_PLSH_WOO; $_PLSH_WOO->product_get_label(); ?>
                
				<?php if(!empty($thumb_ids)) : ?>
					<div class="controls">
						<a href="#" class="btn-symbol-1 <?php echo esc_attr($unique_slider_id); ?>_prev"><i class="fa fa-angle-left"></i></a>
						<a href="#" class="btn-symbol-1 <?php echo esc_attr($unique_slider_id); ?>_next"><i class="fa fa-angle-right"></i></a>
					</div>
				<?php endif; ?>
			

            <?php else : ?>  

                <?php echo '<div class="image active placeholder" style="background-image: url(' . wc_placeholder_img_src() . ');"></div>'; ?>

            <?php endif; ?>

        </div>

    </div>
    
    <?php if(!empty($thumb_ids)) : ?>
    <div class="row">

        <div class="thumbs">
            <div class="thumb-images" id="<?php echo esc_attr($unique_slider_id); ?>">
                <?php
                $has_thumbs = true;
                echo '<a href="#" class="active"><img src="' . plsh_get_thumbnail('plsh_widget_item', true) . '" alt=""></a>';

                foreach($thumb_ids as $item)
                {
                    if($item['type'] != 'variant' || plsh_gs('show_variant_thumbs') != 'off')
                    {
                        $id = $item['id'];
                        $img = wp_get_attachment_image_src( $id, 'plsh_widget_item' );
                        echo '<a href="#" class="thumb-type-' . esc_attr($item['type']) . '"><img src="' . esc_url($img[0]) . '" alt=""></a>';
                    }
                }
                ?>
            </div>
        </div>

    </div>
    <?php endif; ?>

    <?php if(plsh_gs('show_variant_thumbs') == 'off') : ?>
        <div class="hidden slider-variant-guide" <?php
        
        echo ' data-variant-default="' . plsh_get_thumbnail('plsh_product_single', true) . '" ';
        
        foreach($thumb_ids as $item)
        {
            if($item['type'] == 'variant')
            {
                echo ' data-variant-' . $item['variation_id'] . '="' . $item['img'] . '" ';
            }
        }
        
        echo '></div>';
    endif; ?>
</div>
<?php
    $product_image_content = ob_get_contents();
    ob_end_clean();
?>

<div class="col image-col-wrapper<?php if(!$has_thumbs) { echo ' no-thumbs'; }?>">
	<?php echo $product_image_content; ?>
</div>

另一个2.内容产品

<?php
/**
 * The template for displaying product content within loops.
 *
 * Override this template by copying it to yourtheme/woocommerce/content-product.php
 *
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 3.4.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

//apply_filters( 'loop_shop_columns', 3 );

global $product, $polaris_woocommerce_loop;

// Ensure visibility
if ( empty( $product ) || ! $product->is_visible() ) {
    return;
}

// Store loop count we're currently on
if ( empty( $polaris_woocommerce_loop['loop'] ) )
    $polaris_woocommerce_loop['loop'] = 0;

// Increase loop count
$polaris_woocommerce_loop['loop']++;

//start row
if ( 0 == ( $polaris_woocommerce_loop['loop'] - 1 ) % $polaris_woocommerce_loop['columns'] || 1 == $polaris_woocommerce_loop['columns'] )
{
    echo '<!-- START PRODUCT ROW -->';
    $polaris_woocommerce_loop['row_open'] = true;
    echo '<div class="row">';
}
?>


<!-- edited here -->



 <div class="col" data-loop="<?php echo $polaris_woocommerce_loop['loop'] ?>"> 

    <?php
    $classes = array('item-single');

    
    if(plsh_gs('show_quick_features') == 'on')
    {
        $classes[] = 'quick-features-enabled';
    }
    
    if(plsh_gs('zoom_catalog_images_on_hover') == 'on')
    {
        $classes[] = 'zoom-enabled';


    }
    
    ?>

    <!--<a href="<?php the_permalink(); ?>">--> 
   <div <?php wc_product_class( $classes ); ?> data-product-id="<?php echo esc_attr($post->ID); ?>"> 

        <?php do_action( 'woocommerce_before_shop_loop_item' ); 
        // echo "<p>hello</p>";
        
        ?>

        <?php
            /**
             * woocommerce_before_shop_loop_item_title hook
             *
             * @hooked woocommerce_show_product_loop_sale_flash - 10
             * @hooked woocommerce_template_loop_product_thumbnail - 10
             */
            do_action( 'woocommerce_before_shop_loop_item_title' );
        ?>
</a>

        <div class="details">
            <?php if(plsh_gs('show_category_trail') == 'on') : ?>
            
                <?php
                $cats = get_the_terms( $post->ID, 'product_cat' );
                if(!empty($cats) > 0) {
                
                $cats_indexed = array();
                    
                //look for cat with parents
                $cat = false;
                foreach($cats as $cat_item)
                {
                    $cats_indexed[$cat_item->term_id] = $cat_item;
                    
                    if($cat_item->parent > 0 && !$cat) 
                    {
                        $cat = $cat_item;
                    }
                }
                
                if(!$cat)
                {
                    $cat = reset($cats);
                }
                ?>
                <div class="path">
                    <?php 
                    if($cat->parent > 0 && !empty($cats_indexed[$cat->parent]))
                    {
                        echo '<a href="' . esc_url(get_term_link($cats_indexed[$cat->parent])) . '">' . $cats_indexed[$cat->parent]->name . '</a>';
                    }
                    
                    echo '<a href="' . esc_url(get_term_link($cat)) . '">' . $cat->name . '</a>';
                    ?>
                </div>
                <?php } ?>
            
            <?php endif; ?>
            
            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            
            <?php
                /**
                 * woocommerce_after_shop_loop_item_title hook
                 *
                 * @hooked woocommerce_template_loop_price - 10
                 */
                do_action( 'woocommerce_after_shop_loop_item_title' );
            ?>


        </div>

        
        <?php if(plsh_gs('show_quick_features') == 'on') : ?>
            <div class="more">
                <?php

                /**
                 * woocommerce_after_shop_loop_item hook
                 *
                 * @hooked woocommerce_template_loop_add_to_cart - 10
                 */
                do_action( 'woocommerce_after_shop_loop_item' ); 
                ?>
                <div class="links">
                    <?php if(plsh_gs('show_quickview') == 'on') : ?>
                        <a href="javascript:void(0);" class="btn-quickview"><i class="fa fa-eye"></i><?php _e('Quickview', 'polaris'); ?></a>
                    <?php endif; ?>
                    
                    <?php if(shortcode_exists('yith_wcwl_add_to_wishlist')) : ?>
                        <?php echo do_shortcode('[yith_wcwl_add_to_wishlist]'); ?>
                    <?php endif; ?>    
                </div>
            </div>
        <?php endif; ?>
        
    </div>
</div>
    
<?php
//end row
if ( 0 == $polaris_woocommerce_loop['loop'] % $polaris_woocommerce_loop['columns'])
{
    $polaris_woocommerce_loop['row_open'] = false;
    echo '</div>';
    echo '<!-- END PRODUCT ROW close-1 -->';
}
?>
    

现在看来,get_permalink()php函数正在获取相应的产品页面。那么,我应该进行哪些更改以实现此目标以及在哪个php文件中?

0 个答案:

没有答案