So, Im trying to display a few images on the home page. Here is the code I have no, and it’s not working:
<div class="expanded row">
{exp:channel:entries channel="portfolio" limit="3" orderby="random" disable="pagination"}
{if '{img_on_home}' == "Yes"}
<div class="large-4 medium-4 columns zero-pad">{home_page_image}</div>
{/if}
{/exp:channel:entries}
</div>
Now, the output of this should look like:
<div class="expanded row">
<div class="large-4 medium-4 columns zero-pad">path/to/image</div>
<div class="large-4 medium-4 columns zero-pad">path/to/image</div>
<div class="large-4 medium-4 columns zero-pad">path/to/image</div>
</div>
I do not understand why this does not work. I have a hunch its something to do with “random” or the “limit”
The idea here is, “img_on_home” is a checkbox, and there is a file (image)associated with it. Would you like to display an image on the home page? Check for yes, then upload the image. The user could upload any amount of images, but I only want to display 3 at random. Makes sense?
How would I go about pulling this off?
Thanks
well, the problem is, it randomly displays the images. When I mean random, it’s like, sometimes one, then two, then none at all, then maybe one, etc…. but never all three at once.
Even tho I have a total of 5 in the DB. I only want to display 3, at random.
Make sense?
Not sure why this happens.
If I run this:
{exp:channel:entries channel="portfolio" disable="pagination"}
<div class="large-4 medium-4 columns zero-pad">{home_page_image}</div>
{/exp:channel:entries}
I get the expected results. For example, I have 9 entries. lets say 4 of them are tagged as described above (show on home). The above code will spit out all entries, and return images as well as “broken images” - this is expected… I’ve chosen all, but only a few entries have this particular image.
Now, if I add limit=”3”, I get the expected results again, with some images broken. Logic says, I should “filter” these, so I add the “if statement” ….. if the checkbox that reads “show on home page only” is checked, then that would be the filter.
Show on home page? yes/no if “show_on_home_page” == yes, then display.
Since there are more than three, randomize these.
So we finally end up with the following:
<div class="expanded row">
{exp:channel:entries channel="portfolio" limit="3" orderby="random" disable="pagination"}
{if '{img_on_home}' == "Yes"}
<div class="large-4 medium-4 columns zero-pad">{home_page_image}</div>
{/if}
{/exp:channel:entries}
</div>
But this fails. I do in fact get random images, sometimes one, sometimes two, and other times none at all… but NEVER three. Ever.
SOOO…. it seems like I need to run the the if statement BEFORE the channel, but that obviously wont work. I pull 3, at random, but we dont know if they are properly tagged yet. then i run the if statement, which will return nothing at all.
So, the question is:
How can i limit by 3 in the if statement… i guess?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.