Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add Adsense Code to Homepage and Category pages after 1st Post
Tagged: ads, adsense, advertisement, post count, widgets
- This topic has 5 replies, 3 voices, and was last updated 10 years, 4 months ago by jhuotari.
-
AuthorPosts
-
August 5, 2014 at 8:54 pm #117243jponlineMember
Hi,
I use the Streamline 2.0.1 Child Theme with Genesis 2.1. I'm trying to add an Adsense banner ad after the 1st post excerpt (just above the picture of the 2nd post) on the Homepage and in all the category pages.
I've searched and tried several things.
I added the following code to the Genesis Simple Hooks Plugin in the genesis_before_loop Hook:
<?php if( is_category() || is_home() ) { ?> GOOGLE ADSENSE CODE <?php } ?>
That works well but it only adds in before the 1st post.
I tried to register widgets in functions.php and all the codes suggested in the detailed post by Brad Dalton here:
Add Content After Any Number of Post Excerpts In Any Type Of Archive
Only the last option works but it shows the add after the 1st title ... and not after the excerpt.
I tried to add the following suggested code but nothing shows up:
add_action( 'genesis_after_entry', 'google_ad' ); function google_ad() { if ( ! ( is_home() || is_category() ) ) return; global $wp_query; if(($wp_query->current_post == 0) || ($wp_query->current_post == 1)) { echo '<div class="adsense">Adsense code here</div>'; } }
Does anybody have any clue how to achieve it with Streamline?
Thanks a lot
August 5, 2014 at 9:54 pm #117258Brad DaltonParticipantIs your version of Streamline running HTML 5 or XHTML markup?
The PHP code i included uses HTML 5 loop hooks so it won't work on old themes running XHTML markup with the old loop hooks.
All code in the post you linked to is tested and works
The different code snippets provide different solutions based on different conditions so may not solve the exact problem you have.
Link to your site please
August 5, 2014 at 10:37 pm #117266Brad DaltonParticipantHere's the screen shot testing the first code snippet in the post you linked to on my site which creates a widget that outputs after the first excerpt.
I tried to add the following suggested code but nothing shows up:
The screen shot also shows the text which it output using another code snippet from the same post you linked to and the code from my site you embedded above.
The banner add you see on the screenshot was added to the widget the code generates and displays after the excerpt on the first post in the archive only which is what you want so why do you state it doesn't work?
Both solutions display content after the excerpt however the code you posted adds it after all excerpts and the code for the widget only after the first post.
Please understand a few things:
The Streamline Pro theme does not include a loop on the front page ( in the home.php file ) so the posts page in this case is the blog page according to your reading settings and the blog page template your use.
You can change this simply my changing the conditional tags which will also enable you to output your add after excerpts on the category archive pages.
The home page and the front page are not the same nor are the conditional tags
August 6, 2014 at 10:55 am #117374jponlineMemberHi Brad,
Thanks for taking the time to answer me. After reading your messages, I updated the Streamline Child Theme from 2.0.1 to 3.0.1 and it did the trick. You were right, it probably wasn't built on HTML5 and that's why it didn't work.
Anyway, now it's perfect and I like how simple you made it on your site and how easy it was to add the widget.
Have a good day and thanks again!
August 6, 2014 at 7:40 pm #117483Brad DaltonParticipantSeptember 11, 2014 at 11:46 pm #124071jhuotariMemberThank you both very much.
Brad, for several months, I've been wanting to insert ad widgets between post excerpts on category archive pages. But I wasn't sure how to insert a different widget after different post excerpts, for example, widget #1 and #2 after post excerpt #1, widget #3 and #4 after excerpt #2, etc. I knew I needed to use a post count somehow, but I wasn't sure how to do that. Now, I have a place to start, thanks to your code. Thank you!
The main reason I want to do this is to get the ads higher in the content flow when our website is viewed on a mobile device, especially a smartphone. Right now, too many of our ads are in the sidebar, which drops below the main content area on a mobile device. And I'm concerned that too many mobile readers might not be seeing those ads, so I'm trying to improve their prominence and effectiveness.
John Huotari
OakRidgeToday.com (We're using a modified version of the News Pro theme.) -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.