180 | | == Main Templates == |
181 | | |
182 | | It is also possible to use your own modified versions of the Trac [http://www.clearsilver.net/ ClearSilver] templates. Note though that this technique is not recommended because it makes upgrading Trac rather problematic: there are unfortunately several dependencies between the templates and the application code, such as the name of form fields and the structure of the template data, and these are likely to change between different versions of Trac. |
183 | | |
184 | | If you absolutely need to use modified templates, copy the template files from the default templates directory (usually in found in `$prefix/share/trac/templates`) into the `templates` directory of the project environment. Then modify those copies to get the desired results. |
185 | | |
186 | | |
187 | | == Adding Google Adsense Services To Your Trac == |
188 | | === Google Adsense For Content - Ads === |
189 | | It's actually pretty simple now that I know it, here it goes. |
190 | | On your trac environment directory, edit '''`site_css.cs`''' and put this inside: |
191 | | {{{ |
192 | | #!css |
193 | | <?cs |
194 | | ################################################################## |
195 | | # Site CSS - Place custom CSS, including overriding styles here. |
196 | | ?> |
197 | | /* For Mozilla and Safari */ |
198 | | *>#content { |
199 | | padding: 0; |
200 | | margin: 15px 140px 0 15px; |
201 | | text-align: left; |
202 | | min-height: 770px; |
203 | | } |
204 | | |
205 | | /* For IE */ |
206 | | * html #content { |
207 | | padding: 0; |
208 | | margin: 15px 140px 0 15px; |
209 | | text-align: left; |
210 | | height: 770px; |
211 | | } |
212 | | |
213 | | #ads { |
214 | | position: absolute; |
215 | | top: 170px; |
216 | | right: 10px; |
217 | | width: 140px; |
218 | | z-index: 1; |
219 | | text-align: right; |
220 | | } |
221 | | }}} |
222 | | Now a bit of explanation. Settings are of course, of topic, if you have doubts, there's a CSS link above in this page, click it, even so I'll explain parts. |
223 | | |
224 | | First we override '''`#content`''', trac's main content div id so we can have space for our ads. The most important part is that '''`140px`''', our right margin. We also set a minimun height(`min-height`) for Mozilla and Safary browsers and `height` for IE browser or else the ads would be on top of the footer in case the wiki page is small enough, which explains why there are two '''`#content`'''. Because IE doesn't respect `min-height`, so it's just work arround that. |
225 | | |
226 | | The '''`width`''' in '''`#ads`''' should only be set if you intend to have multiple ad spaces, for example, a Skyscraper Google Ad, and also a 'Use Firefox...' that google also makes available. If it wasn't set, both ads would show up side by side, wich is not good '''`;]`'''. If you only intend on using a single Skyscrapper Google Ad, you should ommit '''`width`''', why, because if a user has the firefox Ad-Block plugin, and he blocks all ad content from google he'll see the wiki pages with the full width. Neat right, this way we make everyone happy. |
227 | | |
228 | | Now we'll need to add the Google Ads code somewhere right? Edit '''`site_footer.cs`''', and next is an example: |
229 | | {{{ |
230 | | #!text/html |
231 | | <?cs |
232 | | ######################################################################### |
233 | | # Site footer - Contents are automatically inserted after main Trac HTML |
234 | | ?> |
235 | | <div id="ads"> |
236 | | <!--- Start of Google Ad Code --> |
237 | | YOU WOULD PASTE IT HERE |
238 | | |
239 | | |
240 | | <!--- End of Google Ad Code --> |
241 | | </div> |
242 | | }}} |
243 | | |
244 | | Another example is those ads moving up/down everytime you scroll: |
245 | | {{{ |
246 | | #!text/html |
247 | | <?cs |
248 | | ######################################################################### |
249 | | # Site footer - Contents are automatically inserted after main Trac HTML |
250 | | ?> |
251 | | <div id="ads"> |
252 | | <!--- Start of Google Ad Code --> |
253 | | YOU WOULD PASTE IT HERE |
254 | | <!--- End of Google Ad Code --> |
255 | | </div> |
256 | | |
257 | | <!-- ********************************************************************* |
258 | | * You may use this code for free on any web page provided that |
259 | | * these comment lines and the following credit remain in the code. |
260 | | * From http://www.javascript-fx.com |
261 | | **************************************************************** --> |
262 | | <script type="text/javascript"> |
263 | | <!-- |
264 | | function JSFX_FloatTopRight() |
265 | | { |
266 | | var startX = 10, startY = 160; |
267 | | var ns = (navigator.appName.indexOf("Netscape") != -1); |
268 | | var d = document; |
269 | | var px = document.layers ? "" : "px"; |
270 | | function ml(id) |
271 | | { |
272 | | var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id]; |
273 | | if(d.layers)el.style=el; |
274 | | el.sP=function(x,y){this.style.right=x+px;this.style.top=y+px;}; |
275 | | el.x = startX; el.y = startY; |
276 | | return el; |
277 | | } |
278 | | window.stayTopRight=function() |
279 | | { |
280 | | var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop; |
281 | | var dY = (pY > startY) ? pY : startY; |
282 | | ftlObj.y += (dY - ftlObj.y)/8; |
283 | | ftlObj.sP(ftlObj.x, ftlObj.y); |
284 | | setTimeout("stayTopRight()", 40); |
285 | | } |
286 | | ftlObj = ml("ads"); |
287 | | stayTopRight(); |
288 | | } |
289 | | JSFX_FloatTopRight(); |
290 | | //--> |
291 | | </script> |
292 | | }}} |
293 | | |
294 | | The most important line is this one: |
295 | | {{{ |
296 | | ftlObj = ml("ads"); |
297 | | }}} |
298 | | You must match your ads DIV name: |
299 | | {{{ |
300 | | ftlObj = ml("<your_ads_div_name_here>"); |
301 | | }}} |
302 | | |
303 | | === Google Adsense for Search - Search Boxes === |
304 | | As a follow up on the [http://projects.edgewall.com/trac/wiki/TracInterfaceCustomization#GoogleAdsenseForContentAds previous subject], I'll introduce one more way to add income to your Trac env, replacing trac's search box seen on the top right of trac's header for one that Google Adsense provides. First generate the code you need by logging into [http://google.com/adsense Google Adsense] and selecting "Google Adsense for Search", there you find enough info on how to generate it. |
305 | | |
306 | | Now we'll need to add an additional DIV to '''`site_css.cs`''', here it goes: |
307 | | {{{ |
308 | | #!css |
309 | | <?cs |
310 | | ################################################################## |
311 | | # Site CSS - Place custom CSS, including overriding styles here. |
312 | | ?> |
313 | | #GoogleSearch { |
314 | | position: absolute; |
315 | | top: 3px; |
316 | | right: 3px; |
317 | | z-index: 1; |
318 | | } |
319 | | }}} |
320 | | |
321 | | Now you'll need to add the previous generated search box HTML code somewhere. Edit '''`site_header.cs`''' to look something like: |
322 | | {{{ |
323 | | #!text/html |
324 | | <?cs |
325 | | #################################################################### |
326 | | # Site header - Contents are automatically inserted above Trac HTML |
327 | | ?> |
328 | | <div id="GoogleSearch"> |
329 | | <!--- Start of Google Search Box Code --> |
330 | | YOU WOULD PASTE IT HERE |
331 | | <!--- End of Google Search Box Code --> |
332 | | </div> |
333 | | }}} |
334 | | What happens is that the '''`#GoogleSearch`''' DIV is placed on top of Trac's search box, and by this, replacing it. Do NOTE that Trac's search will still be available, you'll just need to click the search button on the navbar. |
335 | | |
336 | | === In Action === |
337 | | Want to see it in action, drop an eye on [http://dev.ufsoft.org/TracWikiTemplates Trac WikiTemplates Plugin] site. |
338 | | |
339 | | '''IMPORTANT: Do read Google's [https://www.google.com/adsense/localized-terms Terms & Conditions], your account will be frozen/deleted and you WON'T GET any amount you had previously earned if you don't FOLLOW THEM.''' |
340 | | |