【问题标题】:Twitter bootstrap spans in dynamic websitesTwitter bootstrap 跨越动态网站
【发布时间】:2013-05-01 22:23:34
【问题描述】:

我应该如何使用 WordPress 等 CMS 生成动态行?

<div class="row-fluid">
  <div class="span6"></div>
  <div class="span6"></div>
  <div class="span6"></div>
  <div class="span6"></div>
</div>

那行不通。

<div class="row-fluid">
  <div class="span6"></div>
  <div class="span6"></div>
</div>
<div class="row-fluid">
  <div class="span6"></div>
  <div class="span6"></div>
</div>

这可行,但我应该如何为行编程后端?

【问题讨论】:

    标签: php html css twitter-bootstrap


    【解决方案1】:

    嗯,你没有足够的描述你想要做什么,所以我假设你正在循环浏览帖子,并将它们全部存储在 $posts 变量中,并且 html 在每个$postcontent属性基本上是我能给你的唯一方向:

    $i=0;
    foreach ($posts as $post):
        if ($i%2==0) echo '<div class="row-fluid">';
          echo '<div class="span6">'. $post->content .'</div>';
        if ($i%2==1) echo '</div>';
        $i++;
    endforeach;
    

    【讨论】:

    • Dave 这正是我必须编写的那种逻辑,非常感谢!这真的很烦人,因为如果你使用 row 而不是 row-fluid 你可以每次只创建一个 span4 div 并且它没有缺陷但是如果你使用 row-fluid 你需要每次添加一行
    • 酷。我看到您是该网站的新手,如果它告诉您您需要知道的内容,您应该接受答案。谢谢!
    • 行集有 3 个项目呢?
    • 这行不通...1 % 2 = 1 第二次迭代将使&lt;div class="span6"&gt;...&lt;/div&gt; 没有父.row-fluid div...
    【解决方案2】:

    亲吻

    /**
     * Le rows to walk
     */
    $rows = array(
        "Can",
        "I",
        "Has",
        "Cheezburger",
        "?"
    );
    
    /**
     * Le columns numbers
     */
    $columns = 2;
    /**
     * Le template for each row
     */
    $rowTemplate = '<div class="row-fluid">%s</div>';
    /**
     * Look at that function, yeah, it's a freaking cool function, it will chunk your array.
     */
    $chuncked = array_chunk($rows, $columns);
    /**
     * Foreach for make cool and magical stuffs
     */
    foreach($chuncked as $chunk){
        $temp = array();
        foreach($chunk as $string){
            $temp[] = sprintf('<div class="span6">%s</div>', $string);
        }
        printf($rowTemplate,implode(null, $temp)). PHP_EOL;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-23
      • 2012-07-18
      • 2017-01-17
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      • 2013-05-22
      • 2014-07-21
      相关资源
      最近更新 更多