October 11

Inserting message or ad only after first post

Displaying a message only at the bottom of the first post on archive and category pages is a popular request. This way, you have the ad in a prominent place at the same time you don’t clog up the entire blog with ads on every post. This is how we did it. The code goes in archive.php or any of the category type templates like author.php, category.php, tag.php or taxonomy.php.

One: Open up your archive.php (or other archive template) in your favorite text editor

Two: Look for the beginning of the WordPress Loop. Before it, add this code.

<?php $first = true; ?>

Three: Scroll to where you want the ad or message to display. In this example, want the ad tho show immediately under the content. And so this code goes after the_content tag.

<?php if ($first) : ?>
<div class="inpostad">Your ad and ad code goes here</div>
<?php $first = false; ?><?php endif; ?>


Four: Save your template (re-upload to your site if you need to) and that’s it! Simple huh?

This screen shot should help you figure out where all of this goes. Click for a larger image


Tags


You may also like

Force cPanel Password Reset

Force cPanel Password Reset
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Get in touch

Name*
Email*
Message
0 of 350