0

以下のコードを書きましたが、

私が欲しいのは、変数が4のときに新しい<li>. 以下のコードでは、{$counter} は常に 1 です。なぜですか? 増やせないもの

  <div id="slider">
            <ul>
                <li>
                {foreach from=$books value=book}
                {counter start=0 print=false assign=mycounter}
            { math equation="x + 1" x=$mycounter assign="counter" }


                {$counter}

                     <div class="video2">

                        <div class="thumb">
                            <div class="kitap"><a href="http://cmkzl.nokta.com/kitaplar/{$book.title}"><img src="{$imageUrl}/{$book.image}" width="145" height="205"></a></div>
                            <div class="kitap_baslik"><strong>{$book.title}</strong></div>

                            <div class="alt_baslik"><em>{$book.description|truncate:65:"..."}</em></div>
                            <div class="yorumlar_btn"><a href="b_u_tirmanirken"><img src="{$imageUrl}/yorumlar_btn.jpg" width="145" height="50"></a></div>
                        </div>
                    </div>
                </li>
                {if $counter is div by 4}
                <li>
                    {/if}
            {/foreach}

             </ul>

      </div>
4

1 に答える 1

0

PHPで答えを教えてくれませんか

<div id="slider">
<ul>
    <li>
<?php
    $counter = 0;
    foreach( $book in $books)
    { ?>              
         <div class="video2">

            <div class="thumb">
                <div class="kitap"><a href="http://cmkzl.nokta.com/kitaplar/<?= $book.title ?>"><img src="<?=$imageUrl?>/<?=$book.image?>" width="145" height="205"></a></div>
                <div class="kitap_baslik"><strong><?=$book.title?></strong></div>

                <div class="alt_baslik"><em><?= truncateString($book.description,65,true,"...")?></em></div>
                <div class="yorumlar_btn"><a href="b_u_tirmanirken"><img src="<?=$imageUrl?>/yorumlar_btn.jpg" width="145" height="50"></a></div>
            </div>
        </div>

    <?php 
        $counter++;
        if($counter == 4){
            $counter = 0; ?>
            </li>
            <li>
    <?php
        }

    }

 function truncateString($str, $chars, $to_space, $replacement="...") {
   if($chars > strlen($str)) return $str;

   $str = substr($str, 0, $chars);

   $space_pos = strrpos($str, " ");
   if($to_space && $space_pos >= 0) {
      $str = substr($str, 0, strrpos($str, " "));
   }

   return($str . $replacement);
 }

    ?>
    </li>
 </ul>

于 2012-05-09T12:59:18.637 に答える