Add Different Content Between Excerpts On Any Archive Page

In this tutorial, i’ll show you the easiest way to add different banners or any type of content between each post in any archive.

One of the reasons this is popular is because most people find their home or blog page receive the most amount of traffic.

Click the image to see what it can look like when finished:

archive banners

The best solution is to create a custom meta box which appears on all or any post edit screens you choose.

There’s 2 steps involved:

  1. Add PHP code for a custom field to your child themes functions.php file
  2. Create a custom meta box using a free plugin named Advanced Custom Fields.

Code For Custom Field

Here’s the code you can use or modify to create the custom field you want.

add_action('genesis_before_entry', 'banner');
function banner() {
if ( is_home() && genesis_get_custom_field('banner') )
echo '<div id="banner">'. genesis_get_custom_field('banner') .'</div>';
}

The above code uses the conditional tag for the home page which you can also change to your blog page or any archive you desire.

It also includes a hook which can be easily changed as well regardless of whether you’re running the old XHTML or new HTML 5 hooks.

Using ACF Plugin For Custom Meta Box

Next step is to create the custom meta box using the Advanced Custom Fields (ACF) plugin and connect it to your custom field which determines where your custom content displays.

Here’s what the new meta box looks like below your main WordPress editor:

meta box

Once you install the plugin, here’s the settings you can use to achieve the same as what you can see in the screenshots.

Add Custom Field

That’s all there is to it.

A few lines of PHP code and configuration of a really powerful plugin that’s been downloaded more than 1.2 million times for one reason. It truly is awesome with a very slick interface!

Other Methods

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.