Jump to content

How to do this?...


OllieMackJames
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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>';
}?>

Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

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