# if: no ad specified; choose at random
if ( $ad_page instanceof NullPage )
{
$ad = $pages->get('parent=1304, sort=random, include=hidden, limit=1');
}
# else: display the specified ad
else
{
$ad = $ad_page;
} # end if
...and then how the ad is displayed plus the ad counter code
$display_sidebar .= $ad->body;
# Update this ad's view count
$ad_views = $ad->ad_views;
$count = ( empty($ad_views) ) ? 1 : $ad_views + 1;
$ad->setOutputFormatting(FALSE);
$ad->set('ad_views', $count);
$ad->save('ad_views');
}
# else:
else
{
$display_sidebar .= $content->sidebar;
} # end if
$display_sidebar .= '</div>' . LF;
} # end loop
} # end if
echo $display_sidebar;
?>
Edit: I got it working, kind of. I had to comment out lines 89-91 to get rid of the error message I kept getting, and use the echo you included instead of having it displayed at line 83.