[英]How do I add php limit and order to the returning children?
Two things really. 真的有两件事。
Really appreciate any guidance on this, been working hard for nights, can't get anything to work :( 非常感谢任何指导,努力工作了整晚,什么都没用:(
<?php
// get all pages
$pages = new TFW_Navigation($pageNav);
$pages = $pages->getNavigation();
foreach ($pages as $index => $topPage)
{
$children = $topPage->getChildren(null,true);
if (!empty($children)) {
foreach($children as $child) {
?>
<article class="<?=$child->ext_column_1 ?>">
<a href="<?= $child->url ?>" class='article-border'>
<img src="<?=$child->ext_column_2 ?>" alt="">
<header>
<h3>
<?= $child->ext_column_3 ?>
</h3>
</header>
<footer>
<p>
<?php echo date("d F Y", strtotime($child->last_modified))."<span class='sprite article-link'></span>" ?>
</p>
</footer>
</a>
</article>
<?php
}
}
}
?>
If more information is needed, please let me know. 如果需要更多信息,请告诉我。
Thanks, Barry 谢谢,巴里
Add a break
statement. 添加一个break
语句。
foreach($children as $childIndex => $child) {
if ($childIndex > 8) {
break;
}
...
}
$firstEight = array_slice($children, 0, 8); // First 8 items
$sql = "SELECT * FROM table WHERE x = y ORDER BY last_modified ASC";
and also you can limit the results from sql . 也可以限制sql的结果。
$sql = "SELECT * FROM table WHERE x = y ORDER BY last_modified ASC LIMIT 0,8";
// Using //使用
<?php
// get all pages
$pages = new TFW_Navigation($pageNav);
$pages = $pages->getNavigation();
foreach ($pages as $index => $topPage)
{
$children = $topPage->getChildren(null,true);
$firstEight = array_slice($children, 0, 8);
if (!empty($firstEight)) {
foreach($firstEight as $child) {
?>
<article class="<?=$child->ext_column_1 ?>">
<a href="<?= $child->url ?>" class='article-border'>
<img src="<?=$child->ext_column_2 ?>" alt="">
<header>
<h3>
<?= $child->ext_column_3 ?>
</h3>
</header>
<footer>
<p>
<?php echo date("d F Y", strtotime($child->last_modified))."<span class='sprite article-link'></span>" ?>
</p>
</footer>
</a>
</article>
<?php
}
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.