Erwin Posted January 15, 2020 Share Posted January 15, 2020 Hi all, I hope someone can help me figure this out ? On my website I am showcasing some featured projects. I am successfully using the following code to 'fetch' 3 random projects: <?php $projects = $pages->find("template=project-details, sort=random, limit=3"); if($projects) { foreach($projects as $p) { // Project stuff here... } } ?> Is there a way to 'target' the first project so I can add some specific HTML mark-up? For example: the first project shows an image, title, date and short description. The following two projects only show a title. Hope my question makes any sense ? Thanks! Erwin Link to comment Share on other sites More sharing options...
3fingers Posted January 15, 2020 Share Posted January 15, 2020 <?php $projects = $pages->find("template=project-details, sort=random, limit=3"); if($projects) { $first_project = $projects->child(); // Got the first child // Do something with it foreach($projects->remove($first_project) as $p) { // Do something else with the other projects... } } ?> Not tested but it should work, there are several other methods indeed. Or... <?php $projects = $pages->find("template=project-details, sort=random, limit=3"); if($projects) { $i = 0; foreach($projects as $p) { if ($i == 0) { // First project } else { // Other projects } $i++; } } ?> 1 Link to comment Share on other sites More sharing options...
Erwin Posted January 15, 2020 Author Share Posted January 15, 2020 Thank you! Works perfect! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now