Jump to content

Can't get list working correctly


joe_ma
 Share

Recommended Posts

On a site for a band I want to list all the gigs of the band, divided in three sections, coming up, today, past gigs.

To produce the list I have the following code:

<?php
	$timestamp = time();
	$t = date("d.m.Y", $timestamp);
	$heute  = $pages->find("parent=/konzertliste/, Datum=$t");
	$gigs = $pages->find("parent=/konzertliste/, Datum>$t, sort=Datum");
	$gigspast = $pages->find("parent=/konzertliste/, Datum<$t, sort=-Datum");
	
	if (count($heute)) {
		echo "<h2>Heute</h2>"; //todays gigs, if any
		echo "<div class='block-group gig_list'>";		
		echo "<p class='block gig_date'>{$heute->Datum}, {$heute->Zeit} Uhr</p>"; //echo date("j. F Y", $page->modified);
		echo "<p class='block gig_ort'><a href='{$heute->url}'>{$heute->Ort}</a></p></div>";
	}
	
	if (count($gigs)) {

	echo "<h2>Demnächst</h2>"; //gigs coming up
	}
			$out = '';

	foreach($gigs as $gig){
		

			$out .= "<div class='block-group gig_list'>";		
			$out .="<p class='block gig_date'>{$gig->Datum}, {$gig->Zeit} Uhr</p>"; //echo date("j. F Y", $page->modified);
			$out .="<p class='block gig_ort'><a href='{$gig->url}'>{$gig->Ort}</a></p></div>";
		}
	echo $out; 

	if (count($gigspast)) {

	echo "<h2>Bisher</h2>"; //past gigs
	}

			$out = '';

	foreach($gigspast as $gigpast){
		
			$out .= "<div class='block-group gig_list'>";		
			$out .="<p class='block gig_date'>{$gigpast->Datum}, {$gigpast->Zeit} Uhr</p>"; //echo date("j. F Y", $page->modified);
			$out .="<p class='block gig_ort'><a href='{$gigpast->url}'>{$gigpast->Ort}</a></p></div>";
		}
	echo $out; 
	
	
?>

While it works as wanted for the gigs coming up and past, it doesn't for todays gig.

On the frontend I get only the following output:

Heute

, Uhr

And when I change the ">" in the fourth line to ">=" it works also correctly and todays gig is also listed in the "Demnächst" part. So why does it not in the todays part?

Thanks for help

Link to comment
Share on other sites

Looks like you're looping through $gigs and $gigspast, but are trying to output $heute directly. Though it's unusual to have several gigs on one day (I guess, don't know the band :)) $heute will return a page collection. 

Try either foreach($heute as $gigheute) { ... } and better rename them vars, or outputting $heute->first()->Datum.

edit: Fixed typo

Edited by marcus
  • Like 1
Link to comment
Share on other sites

Thank you all for these answers – most valuable ones, as always.

You forgot to foreach loop over the gigs of today. $heute is a PageArray, not a Page.

That solved the problem.

trey using Datum=today instead of Datum=$t

Thanks also for this one. :-)

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