Jump to content
Erwin

Show the first page as a featured item

Recommended Posts

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

Share this post


Link to post
Share on other sites
<?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++;
		}
	}
?>

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...