theadventurebite |
Aug 18, 2012 01:29 PM |
How To Add Adsense between Posts without a widget
Hey all,
Thought I would take a second to share how I figured out how to add Adsense between posts 1 and 2 without a widget. Juggledad's great tutorial here on how to do it with a widget was the basis of this, but I decided I didn't like the look of the widget area between the posts.
I am using an older version so I actually had to take 3.7.7's index.php and copy the top part in its entirety to get this to work right.
Here is the full code:
Code:
<?php
list($bfa_ata, $cols, $left_col, $left_col2, $right_col, $right_col2, $bfa_ata['h_blogtitle'], $bfa_ata['h_posttitle']) = bfa_get_options();
get_header();
extract($bfa_ata);
global $bfa_ata_postcount;
?>
<?php /* If there are any posts: */
if (have_posts()) : $bfa_ata_postcount = 0; /* Postcount needed for option "XX first posts full posts, rest excerpts" */ ?>
<?php // Deactivated since 3.6.5
# include 'bfa://content_above_loop';
// Uses the following static code instead: ?>
<?php bfa_next_previous_page_links('Top'); // For MULTI post pages if activated at ATO -> Next/Previous Navigation: ?>
<?php while (have_posts()) : the_post(); $bfa_ata_postcount++; ?>
<?php $show_widget_after_post = 1;
if ($bfa_ata_postcount == ($show_widget_after_post + 1)) { echo '<div align="center" style="padding-bottom:8px; padding-top:3px; ">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4976060676917875";
/* Square Between Posts */
google_ad_slot = "2257642737";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>';} ?>
If you are already on the current version you don't have to copy all of that just place this:
Code:
<?php $show_widget_after_post = 1;
if ($bfa_ata_postcount == ($show_widget_after_post + 1)) { echo '<div align="center" style="padding-bottom:8px; padding-top:3px; ">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4976060676917875";
/* Square Between Posts */
google_ad_slot = "2257642737";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>';} ?>
below this
Code:
<?php while (have_posts()) : the_post(); $bfa_ata_postcount++; ?>
You can adjust the padding and DIV elements around the ad, and of course replace my ad script with yours.
Hope that helps someone!
Dani
|