Jump to content

add 1st image to rendernav function


Fran
 Share

Recommended Posts

Hi guys,

I'm trying to create a function to show the first picture of a page based on the rendernav function in _init.php.

I'm succeding at showing all the images, but i can't find a way to show just the first image.

Thanks in advance for anyhelp & merry christmass !!!

:)

function renderNavImages(PageArray $items) {

	// $out is where we store the markup we are creating in this function
	$out = '';

	// cycle through all the items
	foreach($items as $item) {

		

		//trying to render 1st image

		foreach($item->images as $image) {
			
			//$imagen = $page->image->first();
			
			$out .= "<img src='$image->url' />";
			}

		
			
		// render markup for each navigation item as an <li>
		if($item->id == wire('page')->id) {
			// if current item is the same as the page being viewed, add a "current" class to it
			$out .= "<li class='current'>";
		} else {
			// otherwise just a regular list item
			$out .= "<li>";
		}

		
		
		// markup for the link
		$out .= "<a href='$item->url'>$item->title<br />$item->image</a> ";
	
		// if the item has summary text, include that too
		if($item->summary) $out .= "<div class='summary'>$item->summary</div>";

		// close the list item
		$out .= "</li>";
	}

	// if output was generated above, wrap it in a <ul>
	if($out) $out = "<ul class='nav'>$out</ul>\n";

	// return the markup we generated above
	return $out;
}
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

×
×
  • Create New...