1

我应该如何使用 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>

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

4

2 回答 2

4

/**
 * 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;
}
于 2013-05-07T20:56:26.987 回答
3

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

$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;
于 2013-05-07T20:31:34.527 回答