WordPress首页方式Google Adsense的方法
发布时间:November 11, 2007 分类:WordPress
Google Adsense的一个群里的一个朋友问我的blog的Google Adsense广告是如何方式的,是不是每篇文章自己添加的,我差点无语。
WordPress也不会这么弱吧,其实修改下WordPress的模板就好了
在index.php(默认地址是wp-content/themes/default/index.php)中需要添加广告的位置(一般是< ?php the_content这个代码前面)
加入
< ?php if(in_array($i,array('1','2'))) {?>这里加广告代码< ?php }?>
这步完成了是没有用处滴
还需要添加2处
在本文件的
| < ?php while (have_posts()) : the_post(); ?> |
前加入
| < ?php $i = 1; ?> |
在
| < ?php endwhile; ?> |
前加入
| < ?php $i++; ?> |
现在提出我做的WordPress首页方式Google Adsense的方法的index.php文件的代码(我靠,好长)如下:
| < ?php get_header(); ?> |
| < ?php if (have_posts()) : ?> |
| < ?php $i = 1; ?> |
| < ?php while (have_posts()) : the_post(); ?> |
| <div class="post" id="post-<?php the_ID(); ?>"><br /><h2 class="posttitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="到《< ?php the_title(); ?>》的永久链接">< ?php the_title(); ?></a></h2><br /><p class="authordate"><span>< ?php the_time('Y') ?>年< ?php the_time('m') ?>月< ?php the_time('j') ?>日 < ?php the_time('A') ?> < ?php the_time('i') ?>:< ?php the_time('s') ?> | 作者:< ?php the_author_posts_link(); ?></span></p><br /><div class="entry">< ?php if(in_array($i,array('1','2'))) {?><div class="rightcontent">11111</div>< ?php }?><br /> |
| < ?php the_content('<br />查看全文 »'); ?></div><br /><p class="postmetadata">分类:< ?php the_category(', ') ?> | < ?php comments_popup_link("没有评论","评论(1)","评论(%)"); ?> < ?php edit_post_link('编辑',' | ',''); ?></p></div> |
| < ?php $i++; ?> |
| < ?php endwhile; ?> |
| <div class="navigation"><div class="alignleft">< ?php posts_nav_link('','','« 上一页') ?></div><br /><div class="alignright">< ?php posts_nav_link('','下一页 »','') ?></div></div> |
| < ?php else : ?><br /><h2 class="center">没有找到结果。您可在右侧搜索框中重新尝试</h2> |
| < ?php endif; ?> |
| < ?php get_sidebar(); ?> |
| < ?php get_footer(); ?> |

沙发自己做
谢谢,来顶了,学习
学习,现在虽然不放AD,但以后可能用上,谢谢水水提供
非常感谢,很好的文章,博客排名也不错。谢了。