Jump to content

Related projects


Jon E
 Share

Recommended Posts

Hi,

I have created a page field type called related_projects.

I want to output this on a template. I need to limit it to 2 and to:

- Find the project name

- The first image from a field named images

Can anyone help me please?

I've really had a good look but totally stuck, especially with the image...

Thanks so much.

Jon

Link to comment
Share on other sites

you mean like this?

<?php

$relatedProjects = $pages->find("template=project,limit=2");

foreach($relatedProjects as $rp) {
	echo "<h2>{$rp->title}</h2>";
	echo '<img src="' . $rp->images->first()->url . '" alt='' />';
}
  • Like 2
Link to comment
Share on other sites

Hi,

Got it working with the below, thanks so much.

Does anyone know how I can only show the #related_projects div if I have options selected?

Seems to be showing on all pages currently.

Sorry to be annoying and thanks so much.

Jon


<?php if($page->related_projects):?>
<div id="related_projects">
<h2>You might like...</h2>

<?php

$relatedProjects = $page->related_projects->find("limit=2");

   

foreach($relatedProjects as $rp) {
    echo "<li><a href='{$rp->url}'><img src='{$rp->images->first()->url}'>";
    echo "<h3>{$rp->title}</h3></a></li>";
}

?>

</div>
<?php endif; ?>
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...