相关疑难解决方法(0)

PHP:如何确定循环的每个第N次迭代?

我希望通过XML发布每3个帖子后回显一个图像这里是我的代码:

<?php
// URL of the XML feed.
$feed = 'test.xml';
// How many items do we want to display?
//$display = 3;
// Check our XML file exists
if(!file_exists($feed)) {
  die('The XML file could not be found!');
}
// First, open the XML file.
$xml = simplexml_load_file($feed);
// Set the counter for counting how many items we've displayed.
$counter = 0;
// Start the loop to display each item.
foreach($xml->post as $post) {
  echo ' 
  <div style="float:left; width: 180px; …
Run Code Online (Sandbox Code Playgroud)

html php loops

52
推荐指数
4
解决办法
9万
查看次数

循环浏览WordPress帖子,并将每个X帖子包装在DIV中

注意:这是一个自我问答

在WordPress中构建不对称网格布局时,通常需要将每个X帖子包装在div中,如下所示:

div
    post
    post
/div
div
    post
    post
/div
div
    post
    post
/div
Run Code Online (Sandbox Code Playgroud)

我想避免使用模运算符,因为它很快就会混淆.

php wordpress loops modulo

4
推荐指数
1
解决办法
1905
查看次数

标签 统计

loops ×2

php ×2

html ×1

modulo ×1

wordpress ×1