Add Content After Any Number of Post Excerpts In Any Type Of Archive

In this tutorial, i’ll provide the working code which displays a new widget after any post in any type of archive.

Here’s the screenshot from my local installation of WordPress.

content after excerpt

You can easily change the number from 1 for the first post excerpt to any number.

And you can also easily change the conditional tag to suit your own requirements.

The code uses genesis hooks however you can easily change it to something like woo_after or thesis_after. Please check your themes hook reference first.

Widget After First Excerpt On Front Page Archive

Related Tutorials


Comments

12 responses to “Add Content After Any Number of Post Excerpts In Any Type Of Archive”

  1. […] Add Content After Any Number of Post Excerpts In Any Type Of Archive […]

  2. Hi Brad

    Thanks for the code.
    I have used it successfully for few months.
    But now its giving problem in chrome browser. the ad is overlapping with the excepts. this problem is not happening in mozilla or internet explorer.
    2ndly, your site is not visible in india. it shows error “under maintainence”. so i am checking it via proxy.

    Thanks for your valuable tutorials and codes.

    Regards
    Amit

    1. Brad Dalton Avatar
      Brad Dalton

      Hi Amit

      Support information. http://wpsites.net/registration/

  3. Brad,

    I used a slightly modified version of this code to successfully add a widget after the first post excerpt on category pages.

    However, I’ve been unable to replicate it to properly create new unique widgets after the second and third excerpts. I was able to create new Widgets #2 and #3, but they all show up right under Widget #1 (i.e., after post excerpt #1 and not after post excerpt #2 and post excerpt #3).

    Ideally, I’d like to be able to replicate your code, or use a modified version of it, to create up to about 10 widget sections in the main content area on category pages. Is that possible?

    Here’s the code I used. The first widget works properly, but the second and third don’t.

    Any help you can provide will be greatly appreciated.

    John Huotari
    OakRidgeToday.com

    [code]
    //* Hook after post excerpt category ad No. 1 on Sept. 19, 2014 */

    add_action( ‘genesis_after_entry’, ‘news_after_post_excerpt_category_ad_1’ );

    function news_after_post_excerpt_category_ad_1() {
    global $post_count;

    ++$post_count;

    if ( ( is_category() ) && 1 == $post_count ) {

    if ( is_active_sidebar( ‘after-post-excerpt-category-ad-1’ ) )

    genesis_widget_area( ‘after-post-excerpt-category-ad-1’, array(
    ‘before’ => ”,
    ‘after’ => ”,
    ) );

    }

    }

    //* Hook after post excerpt category ad No. 2 on Oct. 13, 2014 */
    add_action( ‘genesis_after_entry’, ‘news_after_post_excerpt_category_ad_2’ );

    function news_after_post_excerpt_category_ad_2() {
    global $post_count;

    ++$post_count;

    if ( ( is_category() ) && 2 == $post_count ) {

    if ( is_active_sidebar( ‘after-post-excerpt-category-ad-2’ ) )

    genesis_widget_area( ‘after-post-excerpt-category-ad-2’, array(
    ‘before’ => ”,
    ‘after’ => ”,
    ) );

    }

    }

    //* Hook after post excerpt category ad No. 3 on Oct. 13, 2014 */
    add_action( ‘genesis_after_entry’, ‘news_after_post_excerpt_category_ad_3’ );

    function news_after_post_excerpt_category_ad_3() {
    global $post_count;

    ++$post_count;

    if ( ( is_category() ) && 3 == $post_count ) {

    if ( is_active_sidebar( ‘after-post-excerpt-category-ad-3-left’ ) || is_active_sidebar( ‘after-post-excerpt-category-ad-3-right’ ) ) {

    echo ”;

    genesis_widget_area( ‘after-post-excerpt-category-ad-3-left’, array(
    ‘before’ => ”,
    ‘after’ => ”,
    ) );

    genesis_widget_area( ‘after-post-excerpt-category-ad-3-right’, array(
    ‘before’ => ”,
    ‘after’ => ”,
    ) );

    echo ”;

    }

    }

    }

    /** Register after post excerpt ad widget #1 on category pages on Sept. 19, 2014 */
    genesis_register_sidebar( array(
    ‘id’ => ‘after-post-excerpt-category-ad-1’,
    ‘name’ => __( ‘After Post Excerpt Category Ad One’, ‘news’ ),
    ‘description’ => __( ‘This is the after post excerpt category ad No. 1.’, ‘news’ ),
    ) );
    /** Register after post excerpt ad widget #2 on category pages on Oct. 13, 2014 */
    genesis_register_sidebar( array(
    ‘id’ => ‘after-post-excerpt-category-ad-2’,
    ‘name’ => __( ‘After Post Excerpt Category Ad Two’, ‘news’ ),
    ‘description’ => __( ‘This is the after post excerpt category ad No. 2.’, ‘news’ ),
    ) );
    /** Register after post excerpt ad widget #3 left on category pages on Oct. 13, 2014 */
    genesis_register_sidebar( array(
    ‘id’ => ‘after-post-excerpt-category-ad-3-left’,
    ‘name’ => __( ‘After Post Excerpt Category Ad Three Left’, ‘news’ ),
    ‘description’ => __( ‘This is the after post excerpt category ad No. 3 left.’, ‘news’ ),
    ) );
    /** Register after post excerpt ad widget #3 right on category pages on Oct. 13, 2014 */
    genesis_register_sidebar( array(
    ‘id’ => ‘after-post-excerpt-category-ad-3-right’,
    ‘name’ => __( ‘After Post Excerpt Category Ad Three Right’, ‘news’ ),
    ‘description’ => __( ‘This is the after post excerpt category ad No. 3 right.’, ‘news’ ),
    ) );
    [/code]

      1. Thank you, Brad. I’ll take a look, and I very much appreciate it.

        John

  4. Eli Overbey Avatar
    Eli Overbey

    Thanks for all the help. Works great.

  5. Works well but there is some blank space, how could I get rid of that?

    1. Brad Dalton Avatar
      Brad Dalton

      Simply use Firebug to inspect the white space and find the class and change the values for padding and/or margins.

  6. Great stuff, thanks for sharing!

  7. Bob Roman Avatar

    It’s the first time I see this tutorial regarding the Genesis framework…quite good. I remember I asked somebody how do they show content between archive posts and I’ve been told “it’s something custom made”. Glad I found out how to do it.

    1. Brad Dalton Avatar
      Brad Dalton

      Hi Bob

      You can also use that code on any theme simply by changing the hook from genesis_after_entry to a WordPress hook or a theme specific hook.

      Thanks for the comment.

Leave a Reply

Join 5000+ Followers

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