I have added an adsense share function to my WPMU/BP site. I am using the T2 method of adding an adsense unit to show on only the first post on the index page. found here http://www.tamba2.org.uk/wordpress/adsense/ These two parts are used to define and show adsense only on the first post 1st part <?php $postnum = 1; $showadsense1 = 1; ?> Code (markup): 2nd part <?php if ($postnum == $showadsense1) { echo ' <script type="text/javascript"><!-- google_ad_client = <?php get_adsense_code(); ?>; /* xxxxxxxxxxxxxx */ google_ad_slot = "xxxxxxxxx"; google_ad_width = xxx; google_ad_height = xxx; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> '; } ?> <?php $postnum++; ?> Code (markup): Now inside of the second part you will notice <?php get_adsense_code(); ?> Code (markup): after google_ad_client =. What this is doing is showing as is when i am viewing the page source. I believe it to be because of a function inside of a function. My question is would anyone know of a fix for this or is this something that doesnt have a fix. Thank you
try <?php if ($postnum == $showadsense1) { echo ' <script type="text/javascript"><!-- google_ad_client = '.get_adsense_code().'; /* xxxxxxxxxxxxxx */ google_ad_slot = "xxxxxxxxx"; google_ad_width = xxx; google_ad_height = xxx; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> '; } ?> PHP:
Thank you very much for the reply. It now pulls the code correctly but when it does it puts it in a different spot then defined. ie it should be after google_ad_client = but is now above <script type="text/javascript">. It also shows the publisher # on the page. here is a userblog so you can see what it does. http://blogstick.com/alexmaristseaships/
Just for the record, you cant run different Publishers ID's on different google_ad_slots so you will need to use old style google ads or default the ads by removing the line. google_ad_slot = "xxxxxxxxx"; At a glance $postnum++; is posting the number ? Please post your function code that calls the numbers from wherever they are stored then we can give you the correct variable to use.
<?php get_adsense_code(); ?> is the function code that calls for the numbers $postnum++ is the post number and thanks for letting me know about adsense, will adjust
<?php if ($postnum == $showadsense1) { $adsense_code = get_adsense_code(); echo ' <script type="text/javascript"><!-- google_ad_client = "'.$adsense_code.'"; /* xxxxxxxxxxxxxx */ google_ad_width = xxx; google_ad_height = xxx; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> '; } ?> PHP: and remove <?php $postnum++; ?> Assuming get_adsense_code() gets a number thats returned ( thats why I asked for the code ) $adsense_code = get_adsense_code(); will activate the function and $adsense_code will echo it to the page.
The output works correctly but for some reason it still shows it before <script type="text/javascript"> instead of after google_ad_client = if i remove <?php $postnum++; ?> its shows adsense on every post instead of just the first. i have tested removing <?php $postnum++; ?> like you said but the output is the same and adsense is on every post. current code being used <?php if ($postnum == $showadsense1) { $adsense_code = get_adsense_code(); echo ' <script type="text/javascript"><!-- google_ad_client = '.$adsense_code.'; /* 336x280, TOPfirstPOST */ google_ad_width = 336; google_ad_height = 280; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> '; } ?> <?php $postnum++; ?> Code (markup):