[解決済み] 商品一覧ページでのSKU画像表示

フォーラム 使い方全般 [解決済み] 商品一覧ページでのSKU画像表示

  • このトピックには1件の返信、1人の参加者があり、最後にkent0312により10年、 6ヶ月前に更新されました。
2件の投稿を表示中 - 1 - 2件目 (全2件中)
  • 投稿者
    投稿
  • #56314
    kent0312
    参加者

    動作に関するご質問の場合は必ずご記入ください。


    WordPress のバージョン:3.6

    Welcart のバージョン:1.37

    ご利用のテーマ:デフォルトテーマをカスタム

    症状を確認したブラウザ:firefox(mac)

    サーバー(会社名、サービス名):xserver

    SSLの利用: 共用SSL

    WordPress のパーマリンク設定:/%category%/%postname%/


    素晴らしいプラグイン、ありがとうございます。

    いつもお世話になっております。

    現在、商品一覧ページを作成しております。

    「商品一覧から直接カートへ入れたい」のトピックを参考に、

    複数skuがある商品は別々に表示させ、それぞれカートに入れるという仕様になっております。

    さらに、複数skuのある商品画像をSKUコードと紐づけてそれぞれ別の画像を表示させるようにしたいと思っています。

    そこで、ガイド本を参考に、bks_the_itemImageという関数を作成しました。

    以下function.phpに書き込んだ内容

    function bks_the_itemImage($ptitle = NULL, $width = 100, $height = 100, $out ='') {
    global $usces;

    if( empty($ptitle) )
    return;

    $picposts = query_posts(array('post_type'=>'attachment','name'=>$ptitle));
    if( empty($picposts) )
    return;

    $pictid = $picposts[0]->ID;
    $html = wp_get_attachment_image( $pictid, array($width, $height), false );

    if($out == 'return'){
    return $html;
    }else{
    echo $html;
    }
    }

    表示させたい場所に記載する内容

    <?php bks_the_itemImage(usces_the_itemSku('return'), 150, 150); ?>

    これで、商品詳細ページではskuごとの画像を表示させることが出来たのですが、

    商品一覧ページで同じことをすると、"複数skuを表示した商品"以降の商品が表示されなくなってしまいます。

    解決法がわかりましたら、ご教授頂ければと思います。

    以下長いですがコードです。以下コードで表示させた結果が添付の商品画像①です。

    以下コード内、複数SKUのループ部分の

    <?php usces_the_itemImage(0, 150, 150); ?>

    <?php bks_the_itemImage(usces_the_itemSku('return'), 150, 150); ?>

    に置き換えると 添付の商品一覧②のような状態になります。

    複数SKUごとのSKU画像は表示されるのですが、その後の商品が表示されなくなります。

    複数SKUの商品は 1行目右端2つのコリアンダーパウダーです。

    <?php if (have_posts()) : ?>
    <div class="item-wrap">
    <?php while (have_posts()) : the_post(); ?>
    <?php usces_remove_filter(); ?>
    <?php usces_the_item(); ?>
    <?php if(usces_sku_num() === 1) : usces_have_skus(); ?>
    <div class="itembox">
    <?php if ( !usces_have_zaiko_anyone() ) : ?>
    <div class="itemimg sold"><a href="<?php the_permalink() ?>"><?php usces_the_itemImage(0, 150, 150); ?></a></div>
    <h2 id="post-<?php the_ID(); ?>" class="itemtitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf( esc_attr__( 'Permalink to %s', 'uscestheme' ), the_title_attribute( 'echo=0' ) ); ?>"><?php the_title(); ?></a></h2>
    <p class="itemsku">内容量:<?php usces_the_itemSkuDisp(); ?></p>
    <p class="itemprice"><?php usces_the_itemPriceCr(); ?><?php usces_guid_tax(); ?></p>
    <div class="soldout">SOLD OUT</div>
    <p class="linktxt"><a href="<?php the_permalink() ?>">more info...</a></p>
    <?php else : ?>
    <div class="itemimg"><a href="<?php the_permalink() ?>"><?php usces_the_itemImage(0, 150, 150); ?></a></div>
    <h2 id="post-<?php the_ID(); ?>" class="itemtitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf( esc_attr__( 'Permalink to %s', 'uscestheme' ), the_title_attribute( 'echo=0' ) ); ?>"><?php the_title(); ?></a></h2>
    <p class="itemsku">内容量:<?php usces_the_itemSkuDisp(); ?></p>
    <p class="itemprice"><?php usces_the_itemPriceCr(); ?><?php usces_guid_tax(); ?></p>
    <?php
    usces_the_item();
    usces_have_skus()
    ?>
    <?php usces_direct_intoCart($post->ID,usces_the_itemSku('return'), false, 'カートへ入れる'); ?>
    <p class="linktxt"><a href="<?php the_permalink() ?>">more info...</a></p>
    <?php endif; ?>
    </div><!-- end of item-box -->

    <?php elseif(usces_sku_num() > 1) : usces_have_skus(); ?>
    <?php do { ?>
    <div class="itembox">
    <?php if( !usces_have_zaiko() ) : ?>
    <div class="itemimg sold"><a href="<?php the_permalink() ?>"><?php bks_the_itemImage(usces_the_itemSku('return'), 150, 150); ?></a></div>
    <h2 id="post-<?php the_ID(); ?>" class="itemtitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf( esc_attr__( 'Permalink to %s', 'uscestheme' ), the_title_attribute( 'echo=0' ) ); ?>"><?php the_title(); ?></a></h2>
    <p class="itemsku">内容量:<?php usces_the_itemSkuDisp(); ?></p>
    <p class="itemprice"><?php usces_the_itemPriceCr(); ?><?php usces_guid_tax(); ?></p>
    <div class="soldout">SOLD OUT</div>
    <p class="linktxt"><a href="<?php the_permalink() ?>">more info...</a></p>
    <?php else : ?>
    <div class="itemimg"><a href="<?php the_permalink() ?>"><?php usces_the_itemImage(0, 150, 150); ?></a></div>
    <h2 id="post-<?php the_ID(); ?>" class="itemtitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf( esc_attr__( 'Permalink to %s', 'uscestheme' ), the_title_attribute( 'echo=0' ) ); ?>"><?php the_title(); ?></a></h2>
    <p class="itemsku">内容量:<?php usces_the_itemSkuDisp(); ?></p>
    <p class="itemprice"><?php usces_the_itemPriceCr(); ?><?php usces_guid_tax(); ?></p>
    <?php usces_direct_intoCart($post->ID,usces_the_itemSku('return'), false, 'カートへ入れる'); ?>
    <p class="linktxt"><a href="<?php the_permalink() ?>">more info...</a></p>
    <?php endif; ?>
    </div><!-- end of item-box -->
    <?php } while (usces_have_skus()); ?>
    <?php endif; ?>

    <?php endwhile; ?>
    <?php else : ?>
    <div id="post-0" class="post error404 not-found">
    <h2 class="entry-title"><?php _e( 'Not Found', 'uscestheme' ); ?></h2>
    <div class="entry-content">
    <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'uscestheme' ); ?></p>
    <?php get_search_form(); ?>
    </div><!-- .entry-content -->
    </div><!-- #post-0 -->

    <?php endif; ?>

    #67751
    kent0312
    参加者

    長々とすいませんでした。

    自己解決しましたので、お知らせします。

    whileループ内で別のwhileループをまわしていたのですが、

    それを、foreachに変えたところ解決しました。

    お騒がせしました。

    また何かありましたらよろしくお願い致します。

2件の投稿を表示中 - 1 - 2件目 (全2件中)
  • このトピックに返信するにはログインが必要です。