Page 1 of 1

[php] Shifting pages in category

Posted: Sat May 12, 2018 8:11 pm
by bayerberg
I'm listing a couple of pages from each category,

Code: Select all

$categories = getCategories();
 foreach ($categories as $category) {
 ...
    foreach ($category->pages() as $pageKey) {
     $page = buildPage($pageKey);
 ...
  }
}
whats the best way to array_shift() those pages?
want to change the way first one is displayed, having issues :) Any help much appreciated.

Re: [php] Shifting pages in category

Posted: Wed May 16, 2018 6:55 pm
by diego
array shift remove the element first element of the array and assign to a variable, but I don't understand what you want to do ?

Code: Select all

$categories = getCategories();
 foreach ($categories as $category) {
 
    $pagesKeyList = $category->pages();
    $firstPageKey = array_shift( $pagesKeyList );
    $firstPage = buildPage($firstPageKey);
    echo $firstPage->title();
    
    foreach ($category->pages() as $pageKey) {
     $page = buildPage($pageKey);
 ...
  }
}
	

Re: [php] Shifting pages in category

Posted: Fri May 18, 2018 2:29 pm
by bayerberg
thanks :) soon ill release a theme with that implemented :)

Re: [php] Shifting pages in category

Posted: Fri May 18, 2018 2:44 pm
by bayerberg
almost there.

what do i need exactly: i need to list each category. within each category i need to display a couple of pages. i need to style the first one differently to others.

Code: Select all

$categories = getCategories();
 foreach ($categories as $category) {
    $pagesKeyList = $category->pages();
    $firstPageKey = array_shift( $pagesKeyList );
    $firstPage = buildPage($firstPageKey);
    echo $firstPage->title();
    
      foreach ($pagesKeyList as $child) {
     $page = buildPage($child);
 ...
  }
}
	

Re: [php] Shifting pages in category

Posted: Fri May 18, 2018 6:16 pm
by Edi