Insert (few) ads in between the posts on the homepage
-
So i read the great tutorial who is explaining you how to insert one ad on the homepage : https://codex.www.ads-software.com/User:Tomhanna/Adding_Ads_to_Wordpress
so far so good, but i want to insert few ( 3 exactly ) how do i tweak that ?
HERE IS HOW TO DO IT FOR ONE: 1. Edit index.php of your current theme. 2. Look for: <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?> 3. This is called The Loop. Its purpose is to display posts. Just BEFORE that line, insert this code: <?php $postnum = 1; $showads = 1; ?> 4. We've just created two variables, $postnum and $showads. The first will be incremented for every new post displayed. The second variable ($showads) is the number of posts you want to display before seeing ads. Next, find this code: <?php endforeach; else: ?> 5. That line is the end of The Loop. Just BEFORE that line, add this: <?php if ($postnum == $showads) { ?> <<ADD ADVERTISING HERE>> <?php } $postnum++; ?> 6. Make the appropriate changes such as inserting the advertiser's code where noted. The $showads variable can be changed from '1' to whatever post you want it to display after. 7. Save the file.
but if i want to add one ad block after the 3rd post, then 6th and then the 9th posts, how to do it?
Would love some help on this.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Insert (few) ads in between the posts on the homepage’ is closed to new replies.