Jump to content

Stuck with page list


joe_ma
 Share

Recommended Posts

Hello from a newbie

I am playing around with PW for the first time, trying to build some kind of foto blog. So after I followed the steps in Joss’ tutorial for the gallery I modified and tweeked the files a bit to suit my wishes. Seems to work pretty well so far.

Except …

My albums are all in the folder "albums" (as suggested by Joss). So far I have three albums: Azoren, Berlin, Wien.

On each page (and on the page, that gives an overview of the albums) I want to have a list of all the albums. So I took one of Joss’ functions and modified it like so:

    function albumList(){

    	// Get the list of albums
    	$albums = wire("pages")->find("parent=/albums/, template=mat_gallery");
     
    	$out =" ";

    	//Loop through the pages
    	foreach($albums as $album){

    		$out .="<li><a href='{$album->url}'>{$album->title}</a></li>";
	  
     	echo "<ul>$out</ul>";

    	}
    }

What it produces is the following HTML:

<ul>
  <li><a href='/processwire/albums/azoren/'>Azoren</a></li>
</ul>
<ul>
  <li><a href='/processwire/albums/azoren/'>Azoren</a></li>
  <li><a href='/processwire/albums/berlin/'>Berlin</a></li>
</ul>
<ul>
  <li><a href='/processwire/albums/azoren/'>Azoren</a></li>
  <li><a href='/processwire/albums/berlin/'>Berlin</a></li>
  <li><a href='/processwire/albums/wien/'>Wien</a></li>
</ul>

I.e. it keeps repeating the list in a strange way.

I haven't the faintest as to where I went wrong.

Help therefore apreciated very much.

Thanks.

Link to comment
Share on other sites

Hello and welcome!

The line echo "<ul>$out</ul>"; should be outside the foreach. Like this:

foreach($albums as $album){

    $out .="<li><a href='{$album->url}'>{$album->title}</a></li>";

    // <- not here

}

echo "<ul>$out</ul>"; // <- but here
  • Like 2
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...