Displaying items in shop
-----
| Author | Message | |
|---|---|---|
|
Thoul |
||
| Mon Oct 16, 2006 6:24 pm Post subject: re: Displaying items in shop | ||
|
Add this in the php:
Code: if ( $i % 5 ) { $template->assign_block_vars('list_items.break_line', array()); } Then add Zarath's code in the template file before <!-- END list_items --> instead of after it. |
||
|
laisvai |
||
| Wed Oct 18, 2006 1:36 pm Post subject: | ||
|
No something wrong with this %5, now i only can add two columns, then everything is ok, but if i add for ex. 5 it's still two columns, first column is ok, and in second columns item appears only after each five, everything else is just blank in it. Stupid f**** arrays
|
||
|
Zarath |
||
| Wed Oct 18, 2006 10:28 pm Post subject: re: Displaying items in shop | ||
|
An image would be helpful, as I don't really understand what's happening...
|
||
|
Thoul |
||
| Wed Oct 18, 2006 10:45 pm Post subject: re: Displaying items in shop | ||
|
Ok, one more time. Change the
Code: if ( $i % 5 )
To: Code: if ( $i > 0 && (($i+1) % 5 == 0))
I tested this so it does work. You will get some blank space on the last row if you don't have five items for it, but that can be fixed by just adding more items. |
||
|
laisvai |
||
| Thu Oct 19, 2006 11:12 am Post subject: | ||
|
Yes, that worked out
Thank you a lot Now i need to understand how this all worked out. |
||
|
laisvai |
||
| Thu Oct 19, 2006 11:23 am Post subject: | ||
|
laisvai |
||
| Thu Oct 19, 2006 12:51 pm Post subject: | ||
|
Why i can't edit my posts
Thoul can you explain me the diference between this %5 and your sugestion? this %5 is very logical, so what difference? Thanks |
||
|
Thoul |
||
| Thu Oct 19, 2006 9:07 pm Post subject: | ||
|
laisvai wrote: Why i can't edit my posts
I had a little permissions bug, sorry about that. I fixed it. Quote: Thoul can you explain me the diference between this %5 and your sugestion? this %5 is very logical, so what difference?
Thanks Sure, I'll be happy to explain it. The %, when used like this, gives the remainder from dividing $i by 5. If $i is 0, 5, 10, or any multiple of 5, the result is 0. For any other value of $i, the result will be some other non-zero number. In this case, and most others, $i starts at 0 and counts upword. So for the first item, $i is 0, for the second item $i is 1, for the third item $i is 2, and so on. The if ( $i % 5) we tried first triggers when the remainder is a non-zero number. That means it will trigger the break on the second item, third item, fourth item, and fifth item. The if ( $i > 0 && (($i+1) % 5 == 0)) is more complex because it has two parts, $i > 0 and ($i+1) % 5 == 0. Both parts have to be true for this whole thing to trigger. In retrospect, the $i > 0 part isn't really needed. It was a left over from a test of another version, to prevent the break from happening for the first item. The second part should handle that, so if ( ($i+1) % 5 == 0 ) should work just as well. There are other ways it could be written, too. The second part does the important work. It gets the remainder of $i + 1, divided by 5. The + 1 is important, because that makes this 0 for every fifth item. This section also compares the remainder to 0, so that it is true, and activates the break, only for every fifth item. |
||
|
Zarath |
||
| Thu Oct 19, 2006 10:32 pm Post subject: re: Displaying items in shop | ||
|
Wouldn't...
if ( !(($i+1) % 5) ) Work as well? $i = 0|+1 = 1/5 = remainder is non-zero, so the first statement isn't needed... |
||
|
Thoul |
||
| Fri Oct 20, 2006 12:56 am Post subject: re: Displaying items in shop | ||
|
Yeah, that would be another way to write it.
I realized the first part wasn't need when I was typing up that explanation. It was left over from another way of writing it that did need it, and I didn't think of removing it at the time. |
||
