會員註冊 / 登入  |  電腦版  |  Jump to bottom of page

JForum中文社群 JForum Chinese Users Community » 對JForum每個主題第一篇文章加上Google AdSense廣告

發表人: andowson, 七段學員
2007-08-21 00:23:01
修改post_show.htm, 找到<!-- Message -->, 在 <span class="postbody">${post.text}</span>前面加上判斷是否為第一篇文章及Google AdSense廣告程式碼即可, 修改後的程式碼範例如下:


<!-- Message -->
<td>
<#if post_index == 0>
<div style="float: right; background-image: url(http://adsense-tw.com/adborder-02.gif);height: 300px; width: 350px;padding-top: 38px;
padding-left: 18px;background-repeat: no-repeat;">
<script type="text/javascript"><!--
google_ad_client = "pub-9570897300865282";
google_ad_width = 300;
google_ad_height = 250;
google_ad_format = "300x250_as";
google_ad_type = "text_image";
//2007-08-20: andowson.com首篇文章
google_ad_channel = "8848213845";
google_ui_features = "rc:6";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
</#if>
<span class="postbody">${post.text}</span>


為便於日後版本升級, 我們可以將Googel AdSense的程式碼另存成獨立網頁, 例如templates/default/google_ad_first_post.htm

<#if post_index == 0>
<div style="float: right; background-image: url(http://adsense-tw.com/adborder-02.gif);height: 300px; width: 350px;padding-top: 38px;
padding-left: 18px;background-repeat: no-repeat;">
<script type="text/javascript"><!--
google_ad_client = "pub-9570897300865282";
google_ad_width = 300;
google_ad_height = 250;
google_ad_format = "300x250_as";
google_ad_type = "text_image";
//2007-08-20: andowson.com首篇文章
google_ad_channel = "8848213845";
google_ui_features = "rc:6";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
</#if>


然後再利用FreeMarker#include指令, 將該網頁include到post_show.htm去

><!-- Message -->
<td>
<#include "google_ad_first_post.htm"/>
<span class="postbody">${post.text}</span>

如此類推到其他Google AdSense的廣告上

參考資料:
http://adsense-tw.com/archives/693




會員註冊 / 登入  |  電腦版  |  Jump to top of page