Tutorial: Insertar Adsense entre las entradas del Index, categorías, etiquetas, etc..

Jhoel Mori

1
Zeta
SEO
Verificación en dos pasos desactivada
Suscripción a IA
Desde
7 Dic 2011
Mensajes
1.732
Bueno lo coloque como dijiste cree 2 post no se si era necesario y no salio mi codigo de adsense ahi te mando el entry.php
PHP:
<?php $thumb = '';
  	  
	$width = get_option('polished_thumbnail_width_usual');
	$height = get_option('polished_thumbnail_height_usual');
	$classtext = 'post_img';
	$titletext = get_the_title();
	
	$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext);
	$thumb = $thumbnail["thumb"]; ?>

<!-- New Post-->
<div class="new_post">
	<h2 class="title"><a href="<?php the_permalink() ?>" title="<?php printf(__ ('Permanent Link to %s', 'Polished'), $titletext) ?>"><?php the_title(); ?></a></h2>
	
	<?php if (get_option('polished_postinfo1') <> '') include(TEMPLATEPATH . '/includes/postinfo.php'); ?>
	
	<div class="postcontent">
		<?php if($thumb <> '') { ?>
			<a href="<?php the_permalink() ?>" title="<?php printf(__ ('Permanent Link to %s', 'Polished'), $titletext) ?>">
				<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext , $width, $height, $classtext); ?>
			</a>
		<?php }; ?>
		
		<?php if (get_option('polished_blog_style') == 'false') { ?>
			<p><?php truncate_post(445); ?></p>
		<?php } else { ?>
			<?php the_content(''); ?>
		<?php }; ?>
  
		<span class="readmore_b"><a class="readmore" href="<?php the_permalink(); ?>"><?php _e('Read More','Polished'); ?></a></span>
		<div class="clear"></div>
	</div>	<!-- end .postcontent -->
</div>
<!-- End Post -->
 

brianerc

1
Dseda
Verificación en dos pasos desactivada
Verificado por Whatsapp
Suscripción a IA
Desde
30 Abr 2009
Mensajes
1.197
Muestrame cómo te ha quedado el index.php y pasame la URL de tu blog!
 

Jhoel Mori

1
Zeta
SEO
Verificación en dos pasos desactivada
Suscripción a IA
Desde
7 Dic 2011
Mensajes
1.732
Ahí esta mi Index
PHP:
<?php if (is_archive()) $post_number = get_option('polished_archivenum_posts');
if (is_search()) $post_number = get_option('polished_searchnum_posts');
if (is_tag()) $post_number = get_option('polished_tagnum_posts'); ?>
<?php get_header(); ?>
	
	<?php global $query_string; query_posts($query_string . "&showposts=$post_number&paged=$paged"); ?>
	
	<div id="wrap">
	<!-- Main Content-->
		<img src="<?php bloginfo('stylesheet_directory');?>/images/content-top.gif" alt="content top" class="content-wrap" />
		<div id="content">
			<!-- Start Main Window -->
			<div id="main">
	                        
				<?php $contador=0; if (have_posts()) : while (have_posts()) : the_post(); ?>

					<?php include(TEMPLATEPATH . '/includes/entry.php'); ?>
  
                              <?php $contador++; ?>
  <?php if ($contador == 2) : ?>
          <script type="text/javascript"><!--
google_ad_client = "ca-pub-2831720998621927";
/* adsensebloquegrande */
google_ad_slot = "3093353587";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
  <?php endif; ?>
                                    				<?php endwhile; ?>

					<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
					else { ?>
						<?php include(TEMPLATEPATH . '/includes/navigation.php'); ?>
					<?php } ?>

				<?php else : ?>
					<?php include(TEMPLATEPATH . '/includes/no-results.php'); ?>
				<?php endif; wp_reset_query(); ?>
			</div>
			<!-- End Main -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Mi web
Enlace eliminado
 

brianerc

1
Dseda
Verificación en dos pasos desactivada
Verificado por Whatsapp
Suscripción a IA
Desde
30 Abr 2009
Mensajes
1.197
Prueba colocar ésto:

PHP:
<?php if ($contador == 2) : ?>
          <script type="text/javascript"><!--
google_ad_client = "ca-pub-2831720998621927";
/* adsensebloquegrande */
google_ad_slot = "3093353587";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
  <?php endif; ?>

Antes del último </div> del entry.php
 

Jhoel Mori

1
Zeta
SEO
Verificación en dos pasos desactivada
Suscripción a IA
Desde
7 Dic 2011
Mensajes
1.732
Tengo que crear mas post para ver si me sale o no

Ya lo hise pero se ve igual

Enlace eliminado
 

brianerc

1
Dseda
Verificación en dos pasos desactivada
Verificado por Whatsapp
Suscripción a IA
Desde
30 Abr 2009
Mensajes
1.197
No, no es necesario continuar agregando artículos, ya con que hayan 3 nomas no importa su fecha debería funcionar
Proba esto como tu index.php :

PHP:
<?php if (is_archive()) $post_number = get_option('polished_archivenum_posts');
if (is_search()) $post_number = get_option('polished_searchnum_posts');
if (is_tag()) $post_number = get_option('polished_tagnum_posts'); ?>
<?php get_header(); ?>
    
    <?php global $query_string; query_posts($query_string . "&showposts=$post_number&paged=$paged"); ?>
    
    <div id="wrap">
    <!-- Main Content-->
        <img src="<?php bloginfo('stylesheet_directory');?>/images/content-top.gif" alt="content top" class="content-wrap" />
        <div id="content">
            <!-- Start Main Window -->
            <div id="main">
                            
                <?php $contador=0; if (have_posts()) : while (have_posts()) : the_post(); ?>

                    <?php include(TEMPLATEPATH . '/includes/entry.php'); ?>
  
                              <?php $contador++; ?>
  <?php if ($contador == 2) { ?>
<!-- aca tu codigo de Google Adsense, no borres este comentario -->
          <script type="text/javascript"><!--
google_ad_client = "ca-pub-2831720998621927";
/* adsensebloquegrande */
google_ad_slot = "3093353587";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
  <?php } ?>
                                                    <?php endwhile; ?>

                    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
                    else { ?>
                        <?php include(TEMPLATEPATH . '/includes/navigation.php'); ?>
                    <?php } ?>

                <?php else : ?>
                    <?php include(TEMPLATEPATH . '/includes/no-results.php'); ?>
                <?php endif; wp_reset_query(); ?>
            </div>
            <!-- End Main -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

He puesto un comentario, no es que sea imprescindible porque no hace nada, pero si lo quiero para revisar el código a ver si llega a ejecutarse el condicional, saludos! :)
 

Jhoel Mori

1
Zeta
SEO
Verificación en dos pasos desactivada
Suscripción a IA
Desde
7 Dic 2011
Mensajes
1.732
Es un problema esto XD te do el index haber que tal y te dejo el entry también ok.
PHP:
<?php if (is_archive()) $post_number = get_option('polished_archivenum_posts');
if (is_search()) $post_number = get_option('polished_searchnum_posts');
if (is_tag()) $post_number = get_option('polished_tagnum_posts'); ?>
<?php get_header(); ?>
	
	<?php global $query_string; query_posts($query_string . "&showposts=$post_number&paged=$paged"); ?>
	
	<div id="wrap">
	<!-- Main Content-->
		<img src="<?php bloginfo('stylesheet_directory');?>/images/content-top.gif" alt="content top" class="content-wrap" />
		<div id="content">
			<!-- Start Main Window -->
			<div id="main">
	                        
				<?php $contador=0; if (have_posts()) : while (have_posts()) : the_post(); ?>

					<?php include(TEMPLATEPATH . '/includes/entry.php'); ?>
  
                              <?php $contador++; ?>
  <?php if ($contador == 2) { ?>
<!-- aca tu codigo de Google Adsense-->
          <script type="text/javascript"><!--
google_ad_client = "ca-pub-2831720998621927";
/* adsensebloquegrande */
google_ad_slot = "3093353587";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
  <?php } ?>
                                    				<?php endwhile; ?>

					<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
					else { ?>
						<?php include(TEMPLATEPATH . '/includes/navigation.php'); ?>
					<?php } ?>

				<?php else : ?>
					<?php include(TEMPLATEPATH . '/includes/no-results.php'); ?>
				<?php endif; wp_reset_query(); ?>
			</div>
			<!-- End Main -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Entry.php
PHP:
<?php $thumb = '';
  	  
	$width = get_option('polished_thumbnail_width_usual');
	$height = get_option('polished_thumbnail_height_usual');
	$classtext = 'post_img';
	$titletext = get_the_title();
	
	$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext);
	$thumb = $thumbnail["thumb"]; ?>

<!-- New Post-->
<div class="new_post">
	<h2 class="title"><a href="<?php the_permalink() ?>" title="<?php printf(__ ('Permanent Link to %s', 'Polished'), $titletext) ?>"><?php the_title(); ?></a></h2>
	
	<?php if (get_option('polished_postinfo1') <> '') include(TEMPLATEPATH . '/includes/postinfo.php'); ?>
	
	<div class="postcontent">
		<?php if($thumb <> '') { ?>
			<a href="<?php the_permalink() ?>" title="<?php printf(__ ('Permanent Link to %s', 'Polished'), $titletext) ?>">
				<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext , $width, $height, $classtext); ?>
			</a>
		<?php }; ?>
		
		<?php if (get_option('polished_blog_style') == 'false') { ?>
			<p><?php truncate_post(445); ?></p>
		<?php } else { ?>
			<?php the_content(''); ?>
		<?php }; ?>
  
		<span class="readmore_b"><a class="readmore" href="<?php the_permalink(); ?>"><?php _e('Read More','Polished'); ?></a></span>
		<div class="clear"></div>
	</div>	<!-- end .postcontent -->
<?php if ($contador == 2) : ?>
          <script type="text/javascript"><!--
google_ad_client = "ca-pub-2831720998621927";
/* adsensebloquegrande */
google_ad_slot = "3093353587";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
  <?php endif; ?>
</div>
<!-- End Post -->
Y muchas gracias por ayudarme.
 

brianerc

1
Dseda
Verificación en dos pasos desactivada
Verificado por Whatsapp
Suscripción a IA
Desde
30 Abr 2009
Mensajes
1.197
Mmmm no entiendo por qué no funciona, intenta esto:

el index:

PHP:
<?php if (is_archive()) $post_number = get_option('polished_archivenum_posts');
if (is_search()) $post_number = get_option('polished_searchnum_posts');
if (is_tag()) $post_number = get_option('polished_tagnum_posts'); ?>
<?php get_header(); ?>
    
    <?php global $query_string; query_posts($query_string . "&showposts=$post_number&paged=$paged"); ?>
    
    <div id="wrap">
    <!-- Main Content-->
        <img src="<?php bloginfo('stylesheet_directory');?>/images/content-top.gif" alt="content top" class="content-wrap" />
        <div id="content">
            <!-- Start Main Window -->
            <div id="main">
                            
                <?php $contador=0; if (have_posts()) : while (have_posts()) : the_post(); ?>

                    <?php include(TEMPLATEPATH . '/includes/entry.php'); ?>
                                                    <?php endwhile; ?>

                    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
                    else { ?>
                        <?php include(TEMPLATEPATH . '/includes/navigation.php'); ?>
                    <?php } ?>

                <?php else : ?>
                    <?php include(TEMPLATEPATH . '/includes/no-results.php'); ?>
                <?php endif; wp_reset_query(); ?>
            </div>
            <!-- End Main -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

y el entry.php:

PHP:
<?php $thumb = '';
        
    $width = get_option('polished_thumbnail_width_usual');
    $height = get_option('polished_thumbnail_height_usual');
    $classtext = 'post_img';
    $titletext = get_the_title();
    
    $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext);
    $thumb = $thumbnail["thumb"]; ?>

<!-- New Post-->
<div class="new_post">
    <h2 class="title"><a href="<?php the_permalink() ?>" title="<?php printf(__ ('Permanent Link to %s', 'Polished'), $titletext) ?>"><?php the_title(); ?></a></h2>
    
    <?php if (get_option('polished_postinfo1') <> '') include(TEMPLATEPATH . '/includes/postinfo.php'); ?>
    
    <div class="postcontent">
        <?php if($thumb <> '') { ?>
            <a href="<?php the_permalink() ?>" title="<?php printf(__ ('Permanent Link to %s', 'Polished'), $titletext) ?>">
                <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext , $width, $height, $classtext); ?>
            </a>
        <?php }; ?>
        
        <?php if (get_option('polished_blog_style') == 'false') { ?>
            <p><?php truncate_post(445); ?></p>
        <?php } else { ?>
            <?php the_content(''); ?>
        <?php }; ?>
  
        <span class="readmore_b"><a class="readmore" href="<?php the_permalink(); ?>"><?php _e('Read More','Polished'); ?></a></span>
        <div class="clear"></div>
    </div>    <!-- end .postcontent -->
                           <?php $contador++; ?>
  <?php if ($contador == 2) { ?>
<!-- aca tu codigo de Google Adsense-->
          <script type="text/javascript"><!--
google_ad_client = "ca-pub-2831720998621927";
/* adsensebloquegrande */
google_ad_slot = "3093353587";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
  <?php } ?>
</div>
<!-- End Post -->

Si no funciona, tal vez esté dando algún tipo de problema el include, podrías probar colocar todo lo del entry.php donde esta el include en el index, quedándote algo así:

PHP:
<?php if (is_archive()) $post_number = get_option('polished_archivenum_posts');
if (is_search()) $post_number = get_option('polished_searchnum_posts');
if (is_tag()) $post_number = get_option('polished_tagnum_posts'); ?>
<?php get_header(); ?>
    
    <?php global $query_string; query_posts($query_string . "&showposts=$post_number&paged=$paged"); ?>
    
    <div id="wrap">
    <!-- Main Content-->
        <img src="<?php bloginfo('stylesheet_directory');?>/images/content-top.gif" alt="content top" class="content-wrap" />
        <div id="content">
            <!-- Start Main Window -->
            <div id="main">
                            
                <?php $contador=0; if (have_posts()) : while (have_posts()) : the_post(); ?>

                    <?php $thumb = '';
        
    $width = get_option('polished_thumbnail_width_usual');
    $height = get_option('polished_thumbnail_height_usual');
    $classtext = 'post_img';
    $titletext = get_the_title();
    
    $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext);
    $thumb = $thumbnail["thumb"]; ?>

<!-- New Post-->
<div class="new_post">
    <h2 class="title"><a href="<?php the_permalink() ?>" title="<?php printf(__ ('Permanent Link to %s', 'Polished'), $titletext) ?>"><?php the_title(); ?></a></h2>
    
    <?php if (get_option('polished_postinfo1') <> '') include(TEMPLATEPATH . '/includes/postinfo.php'); ?>
    
    <div class="postcontent">
        <?php if($thumb <> '') { ?>
            <a href="<?php the_permalink() ?>" title="<?php printf(__ ('Permanent Link to %s', 'Polished'), $titletext) ?>">
                <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext , $width, $height, $classtext); ?>
            </a>
        <?php }; ?>
        
        <?php if (get_option('polished_blog_style') == 'false') { ?>
            <p><?php truncate_post(445); ?></p>
        <?php } else { ?>
            <?php the_content(''); ?>
        <?php }; ?>
  
        <span class="readmore_b"><a class="readmore" href="<?php the_permalink(); ?>"><?php _e('Read More','Polished'); ?></a></span>
        <div class="clear"></div>
    </div>    <!-- end .postcontent -->
                           <?php $contador++; ?>
  <?php if ($contador == 2) { ?>
<!-- aca tu codigo de Google Adsense-->
          <script type="text/javascript"><!--
google_ad_client = "ca-pub-2831720998621927";
/* adsensebloquegrande */
google_ad_slot = "3093353587";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
  <?php } ?>
</div>
<!-- End Post -->

                                                    <?php endwhile; ?>

                    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
                    else { ?>
                        <?php include(TEMPLATEPATH . '/includes/navigation.php'); ?>
                    <?php } ?>

                <?php else : ?>
                    <?php include(TEMPLATEPATH . '/includes/no-results.php'); ?>
                <?php endif; wp_reset_query(); ?>
            </div>
            <!-- End Main -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Saludos y se feliz!
 

benny

1
Ni
Verificación en dos pasos desactivada
Verificado por Whatsapp
¡Ha verificado su Paypal!
Suscripción a IA
Desde
3 Ago 2009
Mensajes
3.545
excelente el codigo y el aporte, se agradece!!!!... me funciona de 10 el codigo para rotar los ads y de hecho para quien pregunto, según mis pruebas personales con otros codigos y sitios, este tipo de practicas mejoran el CTR de adsense....

ahora se las pongo mas dificil, hice yo las pruebas con el codigo que dejaron aca pero no me camino...

como sería para mostrar en forma rotativa dos anuncios distintos en el index... o sea por ejemplo, que se muestre debajo del primero y debajo del 5 post?...

saludos
 

Jhoel Mori

1
Zeta
SEO
Verificación en dos pasos desactivada
Suscripción a IA
Desde
7 Dic 2011
Mensajes
1.732
:O muchas pero muchas gracias XD
Ya me funciona solo hise los 2 primeros pasos lo del index y el entry de paso añadí una etiqueta
HTML:
<center></center>
crees que tenga problemas lo hise pa que este centrado el adsense bueno ahora si ya funciono gracias :)
 

brianerc

1
Dseda
Verificación en dos pasos desactivada
Verificado por Whatsapp
Suscripción a IA
Desde
30 Abr 2009
Mensajes
1.197
:O muchas pero muchas gracias XD
Ya me funciona solo hise los 2 primeros pasos lo del index y el entry de paso añadí una etiqueta
HTML:
<center></center>
crees que tenga problemas lo hise pa que este centrado el adsense bueno ahora si ya funciono gracias :)

No hay de qué! cualquier cosa a las órdenes! :)

excelente el codigo y el aporte, se agradece!!!!... me funciona de 10 el codigo para rotar los ads y de hecho para quien pregunto, según mis pruebas personales con otros codigos y sitios, este tipo de practicas mejoran el CTR de adsense....

ahora se las pongo mas dificil, hice yo las pruebas con el codigo que dejaron aca pero no me camino...

como sería para mostrar en forma rotativa dos anuncios distintos en el index... o sea por ejemplo, que se muestre debajo del primero y debajo del 5 post?...

saludos

Mmm, podrías hacerlo más simple sin complicarte, corta el array que se crea en dos array, me explico, para el ejemplo de un index con 5 post:

PHP:
<?php $contador=0; $cantpost = array("1","2","3"); shuffle($cantpost); $mostrarads = array_rand($cantpost,1); $cantpost2 = array("4","5","6"); shuffle($cantpost2); $mostrarads2 = array_rand($cantpost2,1); if (have_posts()) : while (have_posts()) : the_post(); ?>

Luego agregas otro if quedandote así:

PHP:
<?php $contador++; ?>

  <?php 
    if ($contador == 6) {
    }
    else {
    if ($contador == $mostrarads) : ?>
          <!-- aca tu codigo de Google Adsense-->
  <?php endif;
if ($contador == $mostrarads2) : ?>
<!-- aca el otro codigo -->
<?php endif; }
?>

Creo que así podría funcionar, cualquier cosa me dices!

Se feliz :)
 

Dirtyboss

Préstamo
Zeta
Verificación en dos pasos desactivada
Desde
29 Sep 2011
Mensajes
1.660
Excelente, justo lo que andaba buscando de hace algunos días. Muchas gracias, me sirve bastante

Saludos
 

mrN

Beta
Verificación en dos pasos desactivada
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Desde
17 Nov 2011
Mensajes
34
¡Gracias! Justo lo que buscaba :)
 

garlock

Kappa
SEO
Verificación en dos pasos desactivada
Verificado por Whatsapp
Desde
22 Abr 2010
Mensajes
2.740
Por favor, ten en cuenta 📝 que si deseas hacer un trato 🤝 con este usuario, está baneado 🔒.
no funciona en mi blog, me puedes ayudar?

te dejo aqui mi index:
<?php
/**
* Index Template
*
* The index template is a placeholder for all cases that don't have a template file.
* Ideally, all fases would be handled by a more appropriate template according to the
* current page context (for example, `tag.php` for a `post_tag` archive or `single.php`
* for a single blog post).
*
* @package WooFramework
* @subpackage Template
*/

get_header();
global $woo_options;
?>

<!-- #content Starts -->
<?php woo_content_before(); ?>

<div id="content" class="col-full">
<div id="main-sidebar-container">

<!-- #main Starts -->
<?php woo_main_before(); ?>


<div id="main" class="col-left">

<?php get_template_part( 'loop', 'index' ); ?>

</div><!-- /#main -->
<?php woo_main_after(); ?>

<?php get_sidebar(); ?>

</div><!-- /#main-sidebar-container -->

<?php get_sidebar( 'alt' ); ?>

</div><!-- /#content -->
<?php woo_content_after(); ?>

<?php get_footer(); ?>
 

garlock

Kappa
SEO
Verificación en dos pasos desactivada
Verificado por Whatsapp
Desde
22 Abr 2010
Mensajes
2.740
Por favor, ten en cuenta 📝 que si deseas hacer un trato 🤝 con este usuario, está baneado 🔒.
Ese ultimo codigo asi random, me va de maravilla en mi blog: Enlace eliminado

muesto 2 bloques de adsense en random y muestran y desaparecen
 

Dennis

Beta
Verificación en dos pasos desactivada
Desde
25 Ago 2012
Mensajes
74
Por favor, ten en cuenta 📝 que si deseas hacer un trato 🤝 con este usuario, está baneado 🔒.
Exelente tutorial me sirvio mucho..:encouragement:
 

¡Regístrate y comienza a ganar!

Beneficios

  • Gana dinero por participar
  • Gana dinero por recomendarnos
  • Descubre ofertas de empleo diariamente
  • Negocios seguros
  • ¡Información premium y más!

Acceder

¿Ya tienes una cuenta? Accede aquí

Arriba