練功房推薦書單

  • Google!Android 3手機應用程式設計入門(第四版)
  • 賈伯斯傳(軟皮精裝版)
  • 猛虎出閘制霸版:最新OCP Java SE 6 Programmer專業認證(附原始程式碼及範例檔)
  • SCWCD 5 猛虎出閘:Java Web 應用程式專業認證
對JForum每個主題第一篇文章加上Google AdSense廣告  XML
Forum Index » JForum中文社群 JForum Chinese Users Community
Author Message
andowson

六段學員
[Avatar]

Joined: 2007-01-02 22:20:40
Messages: 652
Location: 台北
Offline

修改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

This message was edited 13 times. Last update was at 2011-07-17 22:40:42


分享經驗 累積智慧
[WWW] [MSN]
 
Forum Index » JForum中文社群 JForum Chinese Users Community
Go to: