OllieMackJames Posted March 28, 2013 Share Posted March 28, 2013 I have a sidebar where I want an ad to appear, based on the ad placed in a textarea field. Here's the code I am now trying, but the conditional check does not work. It always shows '<h3 class="col_12 header">NEW Self Help Program...</h3>'; the condition does not work. <?phpif(count($page->sidebar_ad) > 0) {echo '<h3 class="col_12 header">NEW Self Help Program...</h3>';echo '<div class="col_12 sidebar">';echo $page->sidebar_ad;echo '</div>';} ?> What I want to happen is only show all the echo stuff only if the sidebar_ad field is populated. Thanks! Link to comment Share on other sites More sharing options...
OllieMackJames Posted March 28, 2013 Author Share Posted March 28, 2013 OK, found it on the forum somewhere else, I'll leave the answer here for whoever needs it again... (probably me after I forget again..) Here is what works: <?phpif($page->sidebar_ad) {echo '<h3 class="col_12 header">NEW Self Help Program...</h3>';echo '<div class="col_12 sidebar">';echo $page->sidebar_ad;echo '</div>';}?> Link to comment Share on other sites More sharing options...
onjegolders Posted March 28, 2013 Share Posted March 28, 2013 Hi Ollie, you tend to count arrays in PHP. With a textarea field, you're just checking whether it was populated or not so a simple if($page->sidebar_ad) will do it. Link to comment Share on other sites More sharing options...
OllieMackJames Posted March 28, 2013 Author Share Posted March 28, 2013 Hi Ollie, you tend to count arrays in PHP. With a textarea field, you're just checking whether it was populated or not so a simple if($page->sidebar_ad) will do it. Thanks Onjegolders (short for On You Go Type Of Guy?) I'm learning, this way of doing it was just too much repeating work. I managed to get it done like I asked on another post in the forum. Now I only make each ad once in a different page and then call that in via another setting as per http://processwire.com/talk/topic/3185-how-to-reference-image-from-one-page-into-other/ Thanks for thinking along though! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now