joe_ma Posted February 13, 2014 Posted February 13, 2014 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.
diogo Posted February 13, 2014 Posted February 13, 2014 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 2
joe_ma Posted February 13, 2014 Author Posted February 13, 2014 Thanks very much diogo. Sometimes, solutions are very easy … 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now