Forums

[resolved] Simple question about $postcount hat has me baffled--help! (3 posts)

  1. rs11
    Member
    Posted 1 year ago #

    I'd like to use $postcount to display google ads in-between posts in 2-3 different places of a WordPress site.

    I've experimented with this code snippet, and it works great for 1 ad display in-between posts:

    <?php
    $postcount++;
    if($postcount==2){?>

    But if I want to display 3 sets of ads, then how do you put multiple numbers in the $postcount? I tried several coding methods that were rejected, including:

    <?php
    $postcount++;
    if($postcount==( array( 2,4 ) ) ){?>

    Do you have a suggestion? Thanks!

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    http://php.net/manual/en/function.in-array.php

    <?php
    $postcount++;
    if( in_array($postcount, array( 2,4 ) ) ){?>
  3. rs11
    Member
    Posted 1 year ago #

    Yay--you took care of it beautifully, and only a few minutes after I asked the question.

    Thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags