Jump to content

First page


Peter Knight
 Share

Recommended Posts

Hi guys

I have a PW API call which normally outputs all pages as follows

<?php
			if ($page->Related_Downloads->count()) {

			echo "
			  <ul class='uk-tab' data-uk-tab>
			  <li class='uk-active'><a href='#'><strong>Download</strong></a></li>
			  </ul>";

					echo "
					<div class=' side-promo '>";
								foreach($page->Related_Downloads as $download) {
								$thumb = $download->images->first();	
								echo "
								<div class='download-wrapper'>
									<div class='download-thumb'>
									<a href='{$download->file->first()->url}' target='_blank' ><img src='{$thumb->url}' class='download-img'></a>
									</div>

									<div class='download-info'>
									<strong>{$download->title}</strong>
									<br/>
									{$download->summary}
									<br/>
									<a href='{$download->file->first()->url}' class='uk-button uk-button-primary'>Download</a>
									</div>

									<br clear='all'>
								</div>
								"
								;}
				echo "</div>";		
				 }
				?>

if I just want to get the very first page that matches my foreach, why does following throw an error?

foreach($page->first()->Related_Downloads as $download) {
								

 

 

 

Link to comment
Share on other sites

You would need the first Related_Downloads and not the first $page (which is assumably only 1). I think you can use this instead (without foreach):

$download = $page->Related_Downloads->first();

 

Link to comment
Share on other sites

35 minutes ago, tpr said:

You would need the first Related_Downloads and not the first $page (which is assumably only 1). I think you can use this instead (without foreach):


$download = $page->Related_Downloads->first();

 

That's it - thanks :)

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...