【问题标题】:hide first thumbnail from product description page从产品描述页面隐藏第一个缩略图
【发布时间】:2013-07-12 07:49:42
【问题描述】:

我正在尝试隐藏产品描述页面中的第一张图片缩略图

页面链接是http://www.elementsmart.com/product/designer-brass-wooden-box-2/

我写的javascript代码是

<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.thumbnails a.yith_magnifier_gallery:first').hide();
jQuery('.thumbnails a.yith_magnifier_gallery:eq(1)').trigger('click');
});
</script> 

但它不起作用....有人能指出我正确的方向吗?

放大镜的php代码是

<?php

global $post, $product, $woocommerce;     

$columns = apply_filters( 'woocommerce_product_thumbnails_columns', get_option('yith_wcmg_slider_items',floor( yit_shop_single_w() / ( yit_shop_thumbnail_w() + 18 ) )) );  

$attachment_ids = $product->get_gallery_attachment_ids();

// add featured image
/*if ( ! empty( $attachment_ids ) ) array_unshift( $attachment_ids, get_post_thumbnail_id() );

$enable_slider = (bool) ( get_option('yith_wcmg_enableslider') == 'yes' && count(  $attachment_ids ) > $columns );

if ( empty( $attachment_ids ) ) return;*/
?>
<div class="thumbnails<?php echo $enable_slider ? ' slider' : ' noslider' ?>"><?php

echo '<ul class="yith_magnifier_gallery">';


$loop = 0;

foreach ( $attachment_ids as $attachment_id ) {

    $classes = array();

    if ( $loop == 0 || $loop % $columns == 0 )
        $classes[] = 'first';

    if ( ( $loop + 1 ) % $columns == 0 )
        $classes[] = 'last';

    $attachment_url = wp_get_attachment_url( $attachment_id );

    if ( ! $attachment_url )
        continue;

    list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = yit_image( "id=$attachment_id&size=shop_single&output=array" );
    list( $magnifier_url, $magnifier_width, $magnifier_height ) = yit_image( "id=$attachment_id&size=shop_magnifier&output=array" );

    printf( '<li><a href="%s" title="%s" rel="thumbnails" class="%s" data-small="%s">%s</a></li>', yit_image( 'size=shop_magnifier&output=url&id=' . $attachment_id, false ), esc_attr( '' ), implode(' ', $classes), yit_image( 'size=shop_single&output=url&id=' . $attachment_id, false ), yit_image( 'size=shop_thumbnail&id=' . $attachment_id, false ) );

    $loop++;

}

echo '</ul>';
    ?>

    <?php if ( $enable_slider ) : ?>
    <div id="slider-prev"></div>
    <div id="slider-next"></div>
    <?php endif; ?>
    </div>

产品缩略图的代码是

<?php

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

global $post, $woocommerce, $product;
?>
<div class="thumbnails nomagnifier"><?php
$attachments = $product->get_gallery_attachment_ids();

if ($attachments) {

    $loop = 0;
    $columns = apply_filters( 'woocommerce_product_thumbnails_columns', floor( yit_shop_single_w() / yit_shop_thumbnail_w() ) );

    foreach ( $attachments as $attachment_id ) {
        $attachment = get_post( $attachment_id );

        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="prettyPhoto[product-gallery]" class="%s">%s</a>', wp_get_attachment_url( $attachment->ID ), esc_attr( $attachment->post_title ), implode(' ', $classes), yit_image( "id=$attachment->ID&size=" . apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ), false ) );

        $loop++;

    }

}
?></div>

【问题讨论】:

    标签: javascript jquery wordpress woocommerce


    【解决方案1】:

    这可能会解决问题

    $('.yith_magnifier_gallery li:first-child').remove()

    $('.yith_magnifier_gallery li:first-child').hide()

    【讨论】:

    • 嘿,你能帮我删除缩放框中的第一张图片吗.....这里显示的第一张图片是目录页面中的图片......它的尺寸更短,所以不缩放已经上传了更大尺寸的重复图像....所以现在想隐藏默认显示在缩放框中的第一张图像
    • 不清楚你在问什么,我没有你的htmljs 的代码,但我可以模拟点击$('.yith_magnifier_gallery li:eq(1) img').click() 的图像之一
    • 该代码已成功删除缩略图,但它与整个网站上的内容相混淆
    • 特定页面需要它吗?
    • 我用过 确实解决了这个问题。但是我仍然无法从缩放框中删除第一张图片......如果你可以建议,请查看该网站
    【解决方案2】:

    您可以使用.eq() 函数。演示http://jsfiddle.net/yeyene/9HWPE/

    $(document).ready(function() {
        $('.thumbnails yith_magnifier_gallery li').eq(0).remove();
        //$('.thumbnails a.yith_magnifier_gallery:eq(1)').trigger('click');
    });
    

    【讨论】:

    • yaaa 完美解决了......谢谢......嘿,你能帮我删除缩放框中的第一张图片吗......这里显示的第一张图片是来自目录页面的图像......它的尺寸较短,因此不缩放已经上传了较大尺寸的重复图像......所以现在想要隐藏默认情况下显示在缩放框中的第一张图像
    • 你可以使用.remove()代替hide(),像这样...$('.thumbnails yith_magnifier_gallery li').eq(0).remove();
    • 我用过 确实解决了这个问题。但是我仍然无法从缩放框中删除第一张图片......如果你可以建议,请查看该网站
    • 在缩放框中,只有一个链接和图像,你不能删除它,你必须更正你的php代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-06
    • 2019-10-04
    • 2016-07-31
    • 2014-05-27
    • 1970-01-01
    • 2014-04-06
    • 1970-01-01
    相关资源
    最近更新 更多