Log in

View Full Version : loop & customfields


Blackhat
06-16-2008, 11:18 AM
Can I do a while loop in the templates ?

I need to list all the choices choose in a multiple selection box in the postbit template


Thanks for reading! :)

Opserty
06-16-2008, 11:46 AM
Not in templates, do it in a plugin and assign it to a variable. Use this variable in your template.

Blackhat
06-16-2008, 01:35 PM
how would I do that ?

King Kovifor
06-16-2008, 01:49 PM
Add a plugin for postbit_display_start that has the following code:

while($something)
{
$mypostbitvar .= '<html here>';
}

Change the $something to be whatever conditions you want and place the HTML you want where it says <html here>.

Blackhat
06-16-2008, 02:29 PM
I tried this



while($post[field5])
{
$consolebit .= '<img src="/images/consoles/$post[field5].gif" />';
}


but dont seem to work. I put it on the postbit_display_start hook and I just got errors on the site :P

Opserty
06-16-2008, 05:49 PM
Why are you using a while() loop with a custom field as the condition? Are you sure you're not looking for something like foreach() ? You need some kind of list or something to cycle through. I recommend you read up on the basics of PHP (and loops) before you progress further, else we will probably be here all day trying to explain. You can find many tutorials through a quick google search or the php.net site.

Basically you need something to loop through like an array of data (maybe by using explode() on the custom field?) or a database fetch or something but the code you posted doesn't indicate anything of the sort.