dedecms织梦内容管理系统      

--充电学院首页-- | --IT新闻与咨询-- | --电脑应用技术-- | --网络操作技巧-- | --软件硬件教程-- | --精品资料收藏-- | --常用优秀软件-- | --桌面图片欣赏-- | --网络淘金技法-- | --媒体网站资源-- | --火狐专题介绍-- |

  当前位置:主页>其他相关文章>文章内容
实例Wordpress放置Google Adsense和其它广告
来源: 作者:方舟 发布时间:2007-11-15  
stvista
Google Adsense限制了每页最多出现三个Content单元

用Wordpress做的网站如果每篇文章内容的开头都加上了Google Adsense代码的话首页默认文章列表只会显示最多3条GGAD

其他文章前边虽然有了代码,但不会显示,这样就太浪费了~

很多人估计都用一些插件来实现~不过我不喜欢弄一堆插件之类的,感觉太臃肿,效率不高

还是自己动手的好些~

至少在首页加几个广告还是很简单的

首先找到你的WP所使用的模板目录的index.php文件

找到
复制内容到剪贴板
代码:
if(have_posts()):
这句

改成
复制内容到剪贴板
代码:
if(have_posts()):$tmpI = 0;
然后找到
复制内容到剪贴板
代码:
the_content(__('Read the rest of this entry »»'));
改为
复制内容到剪贴板
代码:
$tmpI ++;
If($tmpI<3){
        the_content(__('Read the rest of this entry &raquo;&raquo;'));
}Else{
        the_content_new(__('Read the rest of this entry &raquo;&raquo;'));
}
因为文章显示全部内容的单页调用文章内容也用的the_content函数,所以我在the_content里边加入了Google Adsense的代码~
the_content_new则是显示其他广告代码的函数了,这个是新加的

(当然你也可以不新加一个函数,而是修改the_content,把the_content函数扩充一个参数,根据参数来显示不同的广告~这里我只是简单的做一个演示就不那么做了)

the_content函数的位置是:wp-includes/post-template.php
原来的代码是:
复制内容到剪贴板
代码:
function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
        $content = get_the_content($more_link_text, $stripteaser, $more_file);
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]&gt;', $content);
        echo $content;
}
这里我们把它修改为
复制内容到剪贴板
代码:
function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
        $content = get_the_content($more_link_text, $stripteaser, $more_file);
        $content = "<div style=\"width: 300px; height: 250px; float: right;\">\r\n <script type=\"text/javascript\"><!--\r\n google_ad_client = \"pub-*************\";\r\n //Advert in content\r\n google_ad_slot = \"8466361530\";\r\n google_ad_width= 300;\r\n google_ad_height = 250;\r\n //--></script>\r\n <script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\r\n</script></div>".$content;
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]&gt;', $content);
        echo $content;
}
然后加一个显示其他广告的函数
复制内容到剪贴板
代码:
function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
        $content = get_the_content($more_link_text, $stripteaser, $more_file);
        $content = "<div style=\"width: 300px; height: 250px; float: right;\">\r\n "<div style=\"width: 300px; height: 250px; float: right;\">\r\n <!-- Begin: AdBrite -->\r\n<script type=\"text/javascript\">\r\n   var AdBrite_Title_Color = '66CCCC';\r\n   var AdBrite_Text_Color = '000000';\r\n   var AdBrite_Background_Color = 'FFFFFF';\r\n   var AdBrite_Border_Color = '66CCCC';\r\n</script>\r\n<script src=\"http://ads.adbrite.com/mb/text_group.php?sid=*****&zs=***********\" type=\"text/javascript\"></script>\r\n<div><a target=\"_top\" href=\"http://www.adbrite.com/mb/commerce/purchase_form.php?opid=****&afsid=1\" style=\"font-weight:bold;font-family:Arial;font-size:13px;\">Your Ad Here</a></div>\r\n<!-- End: AdBrite --></div>".$content;</div>".$content;
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]&gt;', $content);
        echo $content;
}
临时申请了个AdBrite来做实验~这里的广告代码可以自己换自己的~

[收藏] [推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
用户名: 新注册) 密码: 匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·免费领取QQ绿钻
·提高电脑运行速度5步曲
·玩转QQ空间营养指数积分免费上涨
·免费领15天绿钻3元钱QQ空间购物
·解决卡巴6.0"无法更新"的方法
·计算机常用英语术语、词汇表8
·使用星空极速上网的请仔细注意提
·QQ攻击之简易的QQ炸弹
·免费注册COM等国际域名教程及工
·IE中“高级”选项详解
·巧用QQ远程协助
·领取免费领取QQ秀2.0
  相关文章
·免费领取QQ绿钻
·如何获得register.com的免费域名
·网上银行用户注意:小心木马病毒
·粘贴QQ密码的方法
·SEO专题讲座:群内整理讲课记录(
·SEO专题讲座:群内整理讲课记录(
·SEO专题讲座:群内整理讲课记录(
·Google如何检测无效点击
·无线局域网与ADSL结合的接入技术
·免费注册COM等国际域名教程及工
·使用星空极速上网的请仔细注意提
·常用的CSS命名规则
  兴趣话题
·
·
·全国地图服务
网站为ZQF个人所有 Power by DedeCms 所有文章来自网络,如有冒犯,请email 或 qq告之,谢谢