I have made a CPT for a featured message on the homepage. What I'm trying to do within a view is to add conditional logic to the view template where it will display the featured message, or default to the standard content that should show in that block if the (wpcf-upcoming-end-time) date field has passed.
Here's my disaster or code:
[wpv-conditional if="( $(wpcf-upcoming-end-time) gte 'TODAY()' )"]
<div class="row">
<div class="col-sm-8"><h1 style="color:#ae11bc; font-size:22px; font-weight:bold; text-align:center; font-family: Oxygen;">[types field='upcoming-title'][/types]</h1>
<p style="color:#4054b2; font-size:17px; text-align:center; margin-top:-14px; font-weight:bold;">[types field='upcoming-sub-title'][/types]<p>
<h3 class="paragraph3">[types field='upcoming-paragraph'][/types]</h3>
<p style="text-align:center; margin-top:0px;">[types field='upcoming-link' title="Click here for more information"][/types]</p>
</div>
<div class="col-sm-4"><div class="image"><img src="/wp-content/uploads/announcement.jpg" width="205px"></div></div></div>
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-upcoming-end-time) lt 'TODAY()' )"]
<div>
<h1 style="text-align:center; font-size:2em; margin-top: -20px; margin-bottom: 5px;"> <span style="color:#000;">OFFER</span> <span style="color:#c0f; font-weight:bold;">HELP?</span></h1>
<hr style="width:200px; border-color:rgba(138,80,224,0.66); border-style:solid; margin: 0 auto;">
<h2 style="text-align:center; color:#47c6b1; padding-top:2px; margin-bottom:2px;">It's easy to make a difference</h2>
<p style="color:#4054b2; font-style:italic; text-align:center;">For any community, <strong>Domestic & Sexual Violence</strong> can easily end up being an "Out of sight, out of mind" situation. While we do our best to let you know what we're up to, sometimes our message can slip through the cracks. Please help us <strong>continue our fight against Domestic & Sexual Violence</strong> by making a <span style="text-decoration: underline;">small monthly donation</span>. It's easy to make a difference!</p>
<div style="max-width:330px; padding: 0 2px; display: flex; justify-content:center; background-color: #ffe3ff; margin: 0 auto; "><a href="/donations/">Make a monthly donation </a> | <a href="/get-involved/">Get Involved</a></div></div>[/wpv-conditional]
I have it sorted to where if there's more than one 'featured' post, that they order themselves correctly and only show one but to save my life I cannot figure out how to show the second 'standard content' when the date has passed for the last featured message. If I take the conditional logic out of the normal content code, it just shows the "No items found" which now says "Working on this.." on the homepage.
What am I doing wrong or how do I make this happen? I've spend 6 hours trying to figure out as I hate to bother you all. Lol.
Thanks for your help!! 🙂 (and seriously.. just try and overlook my inline css disasters and my coding in general). 🙂
Please provide login credentials in the private reply fields here. Let me know where I can see the View on the front-end of your site, and I'll take a closer look.
Looks like there is a limit of 1 result imposed in the View editor. That's why only one post is showing up. Please remove the limit or set it to a different number.
I was hoping to make it to where even if there are several posts made ahead of time, that it would show 1 at a time (closest one to expiring first) and that if all of them had that date field where it was expired, that it would just show the standard content.
With the code below, It's showing the standard content but there's a post that that expires on the 22nd of December so it's still not doing what I'd hoped. *Where we were is that it was showing the 'valid' features but would not show the standard content at all. That's where it was having no results.
[wpv-conditional if="( $(wpcf-upcoming-end-time) gte 'TODAY()' )"]
<div class="row">
<div class="col-sm-8"><h1 style="color:#ae11bc; font-size:22px; font-weight:bold; text-align:center; font-family: Oxygen;">[types field='upcoming-title'][/types]</h1>
<p style="color:#4054b2; font-size:17px; text-align:center; margin-top:-14px; font-weight:bold;">[types field='upcoming-sub-title'][/types]<p>
<h3 class="paragraph3">[types field='upcoming-paragraph'][/types]</h3>
<p style="text-align:center; margin-top:0px;">[types field='upcoming-link' title="Click here for more information"][/types]</p>
</div>
<div class="col-sm-4"><div class="image"><img src="/wp-content/uploads/announcement.jpg" width="205px"></div></div></div>
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-upcoming-end-time) lt 'TODAY()' )" evaluate="false"]
<div>
<h1 style="text-align:center; font-size:2em; margin-top: 5px; margin-bottom: 5px;"> <span style="color:#000;">OFFER</span> <span style="color:#c0f; font-weight:bold;">HELP?</span></h1>
<hr style="width:200px; border-color:rgba(138,80,224,0.66); border-style:solid; margin: 0 auto;">
<h2 style="text-align:center; color:#47c6b1; padding-top:0px; margin-bottom:2px;">It's easy to make a difference</h2>
<p style="color:#4054b2; font-style:italic; text-align:center;">For any community, <strong>Domestic & Sexual Violence</strong> can easily end up being an "Out of sight, out of mind" situation. While we do our best to let you know what we're up to, sometimes our message can slip through the cracks. Please help us <strong>continue our fight against Domestic & Sexual Violence</strong> by making a <span style="text-decoration: underline;">small monthly donation</span>. It's easy to make a difference!</p>
<div style="max-width:330px; padding: 0 2px; display: flex; justify-content:center; background-color: #ffe3ff; margin: 0 auto; "><a href="/donations/">Make a monthly donation </a> | <a href="/get-involved/">Get Involved</a></div></div>
Okay please check now. I removed all the conditionals, because they are not necessary. In the View, I added a Query Filter such that only results that end after today will be displayed. If no results are found, then the default content you originally had in the second conditional will be displayed, because I moved it into the "no results found" area of the View editor.
You are the man. Works perfect and I learned something. Thanks, man!! 😀