Support forums > Tips, tricks, and tutorials

[TIP] Ads Between Listings

(1/19) > >>

keerthi:
Thanks to @teseo. None of the code below are mine.

This procedure will insert an AdSense ad in the middle of your site Ads list, it should put you on the right track if you want to show more:

Theme search-list.php or equivalent:


--- Code: ---<?php // list regular ads
    $adSense_middle_pos = ceil(osc_count_items()/2);
    $ad_counter = 0;
    while(osc_has_items()) { ?>

<tr // etc

// [Normal code here]

?>
</tr>

<?php $ad_counter++;
        if ($ad_counter == $adSense_middle_pos) {
            //AdSense middle ?>
        <tr><td colspan="2">

// [Specific AdSense code here]

</td></tr>
            <?php }

        $class = ($class == 'even') ? 'odd' : 'even';
    } ?>

--- End code ---

The result will be something like as shown in the pic.

rahulk:
I am using minimalist theme(Modern), could you guide me step-by-step how to insert this code for adsense ads between listings.

Thanks

teseo:
Index by theme:

Bender
Bootsnap-Classic
Flatter (Thanks, gnoe)
Infinity
Minimalist (this post)
Modern (this post)
Osclass Wizards
Repurpose
Royal
Twitter

Possible variants (tutorial of sorts :D)

**************************


Hi,

Why, precissely I have used Minimalist 1.2 search-list.php for my example... :D But fine, I'll explain it step by step so it could be useful for other themes too:

1.-


--- Code: ---// list regular ads
while(osc_has_items())
{
--- End code ---

to:


--- Code: ---// list regular ads
                        $adSense_middle_pos = ceil(osc_count_items()/2);
                        $ad_counter = 0;
while(osc_has_items())
{
--- End code ---

2.-


--- Quote ---<tr // etc

// [Normal code here]

?>
</tr>
--- End quote ---

This translates on vanilla Minimalist as:


--- Code: --- <tr class="<?php echo $class; ?>">
<?php
if(osc_images_enabled_at_items())
{
?>
<td class="photo">
<?php
if(osc_count_item_resources())
{
?>
<a href="<?php echo osc_item_url(); ?>" class="image">
<img src="<?php echo osc_resource_thumbnail_url(); ?>" width="75" height="56" title="<?php echo osc_item_title(); ?>" alt="<?php echo osc_item_title(); ?>" />
<?php echo clb_minimalist_format_image_count(); ?>
</a>
<?php
}
else
{
?>
<img src="<?php echo osc_current_web_theme_url('images/no_photo.gif'); ?>" title="" alt="" />
<?php } ?>
</td>
<?php
}
?>
<td class="text">
<h3>
<?php
echo clb_minimalist_format_list_title(osc_item_title(), osc_item_url(), false, true);
?>
</h3>
<p>
<strong>
<?php
if(osc_price_enabled_at_items())
{
echo osc_item_formated_price();
?> - <?php
}
echo osc_item_city();
?> (<?php echo osc_item_region(); ?>) - <?php echo osc_format_date(osc_item_pub_date());
?>
</strong>
</p>
<p><?php echo osc_highlight(strip_tags(osc_item_description())); ?></p>
</td>
</tr>

--- End code ---

You need to identify where the table row (<tr>) for each ad starts and finishes (just for reference, you need to leave this block untouched).

3.- Now replace:


--- Code: --- <?php
$class = ($class == 'even') ? 'odd' : 'even';
}
?>
--- End code ---

with:


--- Code: --- <?php 
        $ad_counter++;
        if ($ad_counter == $adSense_middle_pos) {
            //AdSense middle ?>
        <tr><td colspan="2">

// [Specific AdSense code here]

</td></tr>
            <?php }

        $class = ($class == 'even') ? 'odd' : 'even';
    } 
?>
--- End code ---

Regards

Media DMJ:
 8)

teseo:
***UPDATED***

For Bender you need to modify oc-content/themes/bender/loop.php

This block at the end of the script:


--- Code: ---            while(osc_has_items()) {
                $i++;
                $class = false;
                if($i%4 == 0){
                    $class = 'last';
                }
                $admin = false;
                if(View::newInstance()->_exists("listAdmin")){
                    $admin = true;
                }

                bender_draw_item($class,$admin);

--- End code ---

Replace it with:


--- Code: ---        $adSense_middle_pos = ceil(osc_count_items()/2);
        $ad_counter = 0;
   
        while(osc_has_items()) {
            $i++;
            $class = false;
            if($i%4 == 0){
                $class = 'last';
            }
            $admin = false;
            if(View::newInstance()->_exists("listAdmin")){
                $admin = true;
            }
       
            bender_draw_item($class,$admin);
       
            $ad_counter++;
            if ($ad_counter == $adSense_middle_pos && bender_show_as() == 'list') {
            //AdSense middle ?>
                <li class="listing-card">
           
                    // [Specific AdSense code here]
           
                </li>
            <?php }
--- End code ---

Important note: I've programmed this in a way that will only work for List View, to insert a single "fake regular ad" on Gallery View would scramble the symmetry of the grid layout. :( You'd need to insert 4 AdSenses to keep things pretty...  ???

Regards

Navigation

[0] Message Index

[#] Next page

Go to full version