2013-10-03 90 views
0

我想在我的帖子列表中每十個帖子放一個adsense廣場(250x250)廣告。
我試圖將此代碼添加到我的index.php,職位div中:有一個廣告空間每10個帖子重複

<?php if (have_posts()) : ?> 
<?php $count = 0; ?> 
<?php while (have_posts()) : the_post(); ?> 
<?php $count++; ?> 
    <?php if ($count == 11) : ?> 
     Ad code is here 
      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
      <?php the_excerpt(); ?> 
    <?php else : ?> 
      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
      <?php the_excerpt(); ?> 
    <?php endif; ?> 
<?php endwhile; ?> 
<?php endif; ?> 

它正確地出現了,但職位的所有格式改變出於某種原因。
此外,此代碼僅在第十次發佈後投放廣告,並且在第二十次後不會自動重複,等等。
這實際上並不重要,我可以重複這些數字。

+7

模運算符'如果(($計數%10)== 0)' –

+0

有多少AdSense廣告,你可以在一個頁面上放 – 2013-10-03 20:26:45

+1

太多'<?php'對我的口味的限制。 。 – 2013-10-03 20:31:25

回答

0
 <?php if (have_posts()) : ?> 
    <?php $count = 0; ?> 
    <?php while (have_posts()) : the_post(); ?> 
    <?php $count++; ?> 
    ////////////////////// 
    <?php if($count%10==0){ echo "</br></br></br>"; } ?> 
    /////////////////// 

     <?php if ($count == 11) : ?> 
      Ad code is here 
       <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
       <?php the_excerpt(); ?> 
     <?php else : ?> 
       <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
       <?php the_excerpt(); ?> 
     <?php endif; ?> 
    <?php endwhile; ?> 
    <?php endif; ?> 
+0

它工作,如果我把任何東西,而不是


,廣告代碼除外。如果我把那個wordpress告訴我:解析錯誤:語法錯誤,意外的T_STRING,期待','或';'在這行上<?php if($ count%10 == 0){echo「


」; }> – user2839612

+0

@ user2839612改變所有'


''到


'或'


' - ''
是無效的,並會導致錯誤。 –

+0

我刪除了它,並把廣告的代碼,但它給了我那個錯誤 – user2839612

相關問題