I’m using WordPress and the PODS plugin and created the pod project
. In project i’ve created a set of fields. One of those is project_slide
. If this field has a value, I want to show this in a RoyalSlider on my frontpage.
I’ve started with this piece of code (= one slide).
<?php
$project = pods('project', array('limit' => -1));
while ($project->fetch()) {
echo '<div class="rsContent">';
echo '<img class="rsImg" src="' . $project->display('project_slide') . '" alt="' . $project->display('project_title') . '">';
echo '</div>';
}
?>
The problem is: each project I add, displays in the slider. Even if project_slide
has no value. Any idea how to resolve this?
Just add an if-statement to the loop.
Hide Image example
In my example, I only add the slide when the value isn’t [empty string]
Expand with a detection if the image actually exists
You could expand it with a
file_exists
to also check if it exists (for the items with value, but the image itself doesnt exists). Just make sure the file_exists is 2nd, that way it only checks if the file is present if the string is not empty (if-statements go from left to right)Default image method:
Instead of showing it only when there is an image, you could always show it, but build a default-image logic: