← PHP

Construção de código para colocar diferentes anuncios entre os posts

Lida 5438 vezes

Offline

Eraserhead 
Membro
Mensagens 112 Gostos 0
Troféus totais: 24
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 5 Level 4 Level 3 Level 2 Level 1 100 Posts 50 Posts

Estou com dificuldades na construção do código para colocar 2 anúncios diferentes entre o 1ºpost e o 2º, e entre o 2º post e o 3º. Cada anúncio só pode aparecer na 1ª página.

Já consegui inserir o 1º anúncio, entre o 1º e 2º post, aparecendo somente na 1ª página. Mas não consigo inserir um anuncio diferente entre o 2º e 3º post.

Se alguém puder ajudar... deixo aqui o código:


Código: [Seleccione]
...

<?php $count 1?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ....

...

<?
php include (TEMPLATEPATH '/postdate.php'); ?>


<?php if ($count == 1) : ?>

      <?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>

            <div align="center" id="zzzz"> ANUNCIO </div>

      <?php ?>

<?php endif; $count++; ?>

...
Offline

STronic 
Elite
Mensagens 546 Gostos 8
Feedback +5

Troféus totais: 30
Trófeus: (Ver todos)
Mobile User Search Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

Se só queres na página principal, podes usar o seguinte:

Código: (php) [Seleccione]
...
<?php $count 1?>

<?php if (have_posts()) : while (have_posts()) : the_post(); 
...
<?
php include (TEMPLATEPATH '/postdate.php'); ?>


<?php if (($count == 1) && is_home() && !is_paged()) : ?>
<div align="center" id="zzzz"> ANUNCIO 1 </div>
<?php 
endif; 
$count++;
?>


...

É só mudares o valor do $count == X para onde quiseres mostrar o anuncio...
Offline

Eraserhead 
Membro
Mensagens 112 Gostos 0
Troféus totais: 24
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 5 Level 4 Level 3 Level 2 Level 1 100 Posts 50 Posts

STronic,

Já tinha feito isso e continuou a não funcionar.

Devo estar a fazer alguma coisa mal, coloquei assim:

Código: (php) [Seleccione]
...
<?php $count 1?>

<?php if (have_posts()) : while (have_posts()) : the_post(); 
...
<?
php include (TEMPLATEPATH '/postdate.php'); ?>


<?php if (($count == 1) && is_home() && !is_paged()) : ?>
<div align="center" id="zzzz"> ANUNCIO 1 </div>
<?php 
endif; 
$count++;
?>


<?php if (($count == 2) && is_home() && !is_paged()) : ?>
<div align="center" id="zzzz"> ANUNCIO 2 </div>
<?php 
endif; 
$count++;
?>

...
Offline

STronic 
Elite
Mensagens 546 Gostos 8
Feedback +5

Troféus totais: 30
Trófeus: (Ver todos)
Mobile User Search Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

estás a aumentar o contador 2x...

o $count++ só podes usar no fim dos IFs
Offline

Eraserhead 
Membro
Mensagens 112 Gostos 0
Troféus totais: 24
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 5 Level 4 Level 3 Level 2 Level 1 100 Posts 50 Posts

Também experimentei como dizes, mas fico com o site em branco.
O único erro é esse?
Offline

STronic 
Elite
Mensagens 546 Gostos 8
Feedback +5

Troféus totais: 30
Trófeus: (Ver todos)
Mobile User Search Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

Também experimentei como dizes, mas fico com o site em branco.
O único erro é esse?

Sim, por defeito, isso funcionaria.
A não ser que hajam outras implicações no site.
Offline

Bruno Gaspar 
Membro
Mensagens 242 Gostos 1
Feedback +3

Troféus totais: 18
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 3 Level 2 Level 1 100 Posts 50 Posts 10 Posts

Há uns tempos tive de fazer uma coisa desse género e usei esse método e funcionou

http://devilsworkshop.org/show-adsense-ads-after-first-or-every-post-in-wordpress-blogs-how-to/
http://weblogs.about.com/od/wordpresstutorialstips/ss/AdSenseBtwnPost.htm

São praticamente métodos iguais.
Offline

STronic 
Elite
Mensagens 546 Gostos 8
Feedback +5

Troféus totais: 30
Trófeus: (Ver todos)
Mobile User Search Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

Se tiveres algum plugin de cache instalado, desativa-o ou limpa a cache!
Offline

Eraserhead 
Membro
Mensagens 112 Gostos 0
Troféus totais: 24
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 5 Level 4 Level 3 Level 2 Level 1 100 Posts 50 Posts

Problema resolvido! O problema era algo que não tinha fechado correctamente.

Quero agradecer ao STronic, foi ele que resolveu o problema.

Quando alguém precisar deste código:

Citar
...

<?php $count = 1; ?>


<?php if (have_posts()) : while (have_posts()) : the_post(); ...

...

<?php include (TEMPLATEPATH . '/postdate.php'); ?>


<?php if (($count == 1) && is_home() && !is_paged()) : ?>

            <div align="center" id="zzz">

                     CODIGO ANUNCIO 1

            </div>


<?php endif;  ?>

<?php if (($count == 2) && is_home() && !is_paged()) : ?>

            <div align="center" id="zzzz">

                     CODIGO ANUNCIO 2

            </div>


<?php endif;  ?>
<?php $count++; ?>

...