i have site on cms GetSimple and want to show 10 subpage and load another with ajax.
function getSubMenu($page){This code echo all subpage. How show only 10 subpage and another load after with ajax. Ajax i can do but correct php it is difficult for me. Thank if anyone will answer.$children=getChildren($page); foreach ($children as $subpage){ $title=returnPageField($subpage,'title'); $url=returnPageField($subpage,'slug'); echo '<a href="/'.$url.'.html"> '.$title.'</a>'; }
}
Update
function getSubMenu($page){This code show only 10. How make php function which show more subpage (number from ajax). For example ajax$children=getChildren($page); $i=0; foreach ($children as $subpage){ if($i==10) break; $title=returnPageField($subpage,'title'); $url=returnPageField($subpage,'slug'); echo '<a href="/'.$url.'.html"> '.$title.'</a>'; $i++; }
}
$.ajax({ type: "POST", url: "", context: this, data: { 'num' : '10' }, success: function(data){ console.log(data); }, error: function(data){ console.log('error' + data); } });
You can break out of the foreach loop by using this.
foreach ($children as $subpage){
$title=returnPageField($subpage,'title');
$url=returnPageField($subpage,'slug');
echo '<a href="/'.$url.'.html"> '.$title.'</a>';
$count++;
if($count==10) break;
}