[php] Shifting pages in category

Post Reply
User avatar
bayerberg
Master Bludit
Posts: 68
Joined: Wed Jun 07, 2017 1:05 pm

Sat May 12, 2018 8:11 pm

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.
i do things, check them out on behance | check out startups undiluted - london's startup ecosystem
User avatar
diego
Site Admin
Posts: 716
Joined: Sat May 16, 2015 2:53 pm
Contact:

Wed May 16, 2018 6:55 pm

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);
 ...
  }
}
	
User avatar
bayerberg
Master Bludit
Posts: 68
Joined: Wed Jun 07, 2017 1:05 pm

Fri May 18, 2018 2:29 pm

thanks :) soon ill release a theme with that implemented :)
i do things, check them out on behance | check out startups undiluted - london's startup ecosystem
User avatar
bayerberg
Master Bludit
Posts: 68
Joined: Wed Jun 07, 2017 1:05 pm

Fri May 18, 2018 2:44 pm

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);
 ...
  }
}
	
i do things, check them out on behance | check out startups undiluted - london's startup ecosystem
User avatar
Edi
Site Admin
Posts: 1300
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

Fri May 18, 2018 6:16 pm

Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
Post Reply