Jump to content

Recommended Posts

Posted

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.

<?php
if(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!

Posted

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:

<?php
if($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>';
}?>

Posted

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.

Posted

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!

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...