Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
Hello,
I am creating a news website for a client and I have ad spaces positioned at different places on different pages as seen in the image below:
ad spaces.JPG
ad spaces.JPG (386.87 KiB) Viewed 1091 times


My intention is to create an "ads.php" clonable template with an image upload field and checkboxes field with the options being different ad sizes(in pixels) so that when I upload an ad image and check which size the ad is, it will automatically appear at its correct place on the front end. My problem is how to use the checkbox to filter which ad appears where:
Example:
Code: Select all
<cms:pages masterpage="ads.php" limit="1" filter="checkbox size in pixels">
  <img src="<cms:show ad_img />" alt="ad img" />
....
</cms:pages>


Thank you
Does it need to be a checkbox (i.e. would a single ad image cater to multiple ad sizes)?
If not, you may use radio or dropdown instead and then the filtering would become easier using 'custom_field' parameter of <cms:pages> - http://docs.couchcms.com/tags-reference ... stom_field
Sorry KK, yes a radio button or drop down will work best. Thanks very much for guiding me through. I was able to do it.
Now I want to be able to add expiring dates too so that when an Ad is uploaded, an "end date" can be selected from the back-end(admin page) after which the ad is unposted and a default image(Ad space available image) is show on the front-end.

This is what i have done so far:

On the Ads.php clonable page I have:
Code: Select all
<?php require_once('afropolitanonline-admin/cms.php'); ?>
<cms:template title="Ads" clonable="1" order="50">
<cms:editable
  name='ad'
  label='Advert'
  desc='Upload ad here'
  type='file'
/>
<cms:editable
  name="ad_size"
  label="Ad size"
  desc="Choose size here"
  opt_values='300*300 | 120*40 | 200 * 130'
  type='radio'
/>

</cms:template>

<?php COUCH::invoke(); ?>


And on the front-end I have:
Code: Select all
<cms:pages masterpage='ads.php' custom_field='ad_size=300*300'>
<img src="<cms:show ad />" alt="ad"/>
</cms:pages>
Hi, if you set 'published' date in advanced menu to some future date, i.e. 3 months from now, then a slight change in code helps:

This addition will hide ads that are dated in the past. You may use cms:no_results tag to handle display of default image.
Thanks trendoman. It worked like magic. Now I have another problem: I want to either output the ads I upload or use a google Adsense code so show ads from google. So I am looking at something like this:
Code: Select all
<cms:template name="ads" clonable="1">
<cms:editable
  name='ad'
  label='Advert'
  desc='Upload ad here'
  show_preview='1' preview_width='150'
  type='file'
  order='1'
/>

<cms:editable
  name='ad_size'
  label='Ad size'
  desc='Choose size here'
  opt_values='300*300 | 728*90 | 160 * 600'
  type='radio'
  order='3'
/>

<cms:editable
  name='ad_type'
  label='Ad type'
  desc='Choose ad type'
  opt_values='google adsense | internal ad'
  type='radio'
  order='4'
/>

<cms:editable name='google_adsense_code' label='Adsense code' order="10" desc='Adsense code' type='text'/>
</cms:template>

<cms:pages masterpage='ads.php' limit='1'  custom_field='ad_size=300*300'>
<cms:If custom_field=‘ad_type=google adsense”>
<cms:show google_adsense_code />
<cms:if />
<cms:if  custom_field=‘ad_type=internal ad”>
  <a href="<cms:show ad_link />"><img src="<cms:show ad />" alt=" Ad: <cms:show k_page_title />" /></a>
</cms:if >
<cms:no_results>
Ad space avaialable
</cms:no_results>
</cms:pages>


How do I use if statement with custom fields.
Code: Select all
<cms:pages masterpage='ads.php' limit='1'  custom_field='ad_size=300*300'>
   
    <cms:if ad_type = 'google adsense'>
        <cms:show google_adsense_code />
    <cms:else_if ad_type = 'internal ad'/>
        <a href="<cms:show ad_link />"><img src="<cms:show ad />" alt=" Ad: <cms:show k_page_title />" /></a>
    <cms:else />
        ad not defined
    </cms:if >
   
    <cms:no_results>
    Ad space avaialable
    </cms:no_results>
   
</cms:pages>
Thanks trendoman, will try it out and get back to you
8 posts Page 1 of 1
cron