Welcome to Delicate template
Header
Just another WordPress site
Header

SALEマークがついているかどうか(ColorMeテンプレート)

9月 11th, 2010 | Posted by gau in ColorMe

管理画面で商品名に「SALE」のマークを付加しているか判別する方法。

$product.name(商品名のタグ)に画像が含まれるかどうかを判断し、あればSALEマークの画像名と一致するかselectionで走査する。該当すればture、該当しなければfalseで処理を分岐。selectionの「start」と「loop」を変更すれば、他の画像にも対応可能。

■CODE:

<!-- SALEマーク有無の判断 -->
<{if $product.name|regex_replace:'/.*<img.*/i':'<img' == '<img'}>

    <!-- SALEマークの画像番号に対応したループ -->
    <{section name=cnt start=16 loop=25}>

        <!-- アイコンファイル名を$fooに代入 -->
        <{assign var=foo value='icons'|cat:$smarty.section.cnt.index|cat:'.gif'}>

        <!-- アイコンファイル名が商品名にふくまれているか -->
        <{if $product.name != $product.name|replace:$foo:''}>

            <!-- 含まれている場合にはここにステートメントを入力 -->

        <{/if}>
    <{/section}>
<{/if}>

You can follow any responses to this entry through the RSS 2.0 Both comments and pings are currently closed.