please modify this code (it might be easy)

Discussion in 'PHP' started by diego018, Jul 27, 2007.

  1. #1
    im not great in develop php, so please help me. i got a code, that displays adsense ads if the blog post count is 1. i want it to show adsense ads on first 2 posts (1 and 2) ive tried changed 1 to 1,2 but that doesnt work. heres the code to modify:

    <?php if ($count == 1) : ?><script type="text/javascript">
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <?php endif; $count++; ?>

    please help me, i really need it.
     
    diego018, Jul 27, 2007 IP
  2. jajed

    jajed Peon

    Messages:
    75
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php if ( ($count == 1) || ($count == 2) ) : ?>
     
    jajed, Jul 27, 2007 IP
    diego018 likes this.
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Don't use the deprecated if: endif, use if { }, like so:
    <?php if ($count++ <= 2) : ?>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <?php } ?>
    Code (markup):
    I also took out the other redundant <script> tag.
     
    krt, Jul 27, 2007 IP
    diego018 likes this.
  4. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    umm, just do it if count is less than 3?

    <?php if ($count < 3){ ?>
    <script type="text/javascript">
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <?php } ?>
     
    ecentricNick, Jul 28, 2007 IP
  5. diego018

    diego018 Well-Known Member

    Messages:
    920
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    150
    #5
    i used the jaked method. i was planning to use ecentrinick method, but that method show the ads in the 3 first post. i didnt try krt method. thanks everyone!!
     
    diego018, Jul 28, 2007 IP
  6. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #6
    Does it make a difference? :D Anyway, I prefer <= 2 as it seems more logical. You are putting ads on the first 2 posts, not putting the ads before the 3rd post. Also, your code is not incrementing $count.
     
    krt, Jul 28, 2007 IP