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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...