互联网技术 · 2024年2月14日

如何在Typecho日志列表中插入广告模块,给文章列表添加广告

typecho主题已经初见形状,所以想着在首页列表中插入广告,看看有没有高级的方法。之前在zblogasp中实现的时候是先输出前2篇文章,然后防止广告模块代码,再输出除前2篇文章的其它文章,应该最低效的编程了。

这次百度,刚好看到李学江童鞋有转载,就顺手收藏下,比如在文章列表第三篇文章后面输出一条广告,代码如下:

<ol class=”dp-c”> <li class=”alt”><?php $counter=0; ?></li> <li><?php while($this->next()): ?></li> <li class=”alt”><?php $counter++; ?></li> <li><?php if($counter==4) :?></li> <li class=”alt”>这里填写广告代码</li> <li><?php else: ?></li> <li class=”alt”><?php endif; ?></li> 这是通过if语句判断来实现的,这种方法是不是笨方法我不知道,反正我现在用着没问题。</ol>

index.php里有一行next()): ?>,就是上面代码中的第二行,先在这行代码前面插入一行代码, 然后在next()): ?>这行代码下面插入以下代码:

<ol class=”dp-c”> <li class=”alt”><?php $counter++; ?></li> <li><?php if($counter==4) :?></li> <li class=”alt”>这里填写广告代码</li> <li><?php else: ?></li> <li class=”alt”><?php endif; ?></li> </ol>

文章来源:林三在线

来源地址:https://linsan.net/how-to-insert-ads-for-typecho.html

$.getJSON(“/section/814.json”,function(data){var h = + data[0][title] + : + data[0][description] + ;$(#section-814).append(h);});

$.getJSON(“/section/637.json”,function(data){var channel_id =window.CHANNEL_ID ||0;var channel,default_channel;$.each(data,function(i,r){if (r.channel_id ==0) {default_channel =r;} if (r.channel_id ==channel_id) {channel =r;return false;} }) channel =channel ?channel :default_channel;if (channel &&channel.thumb) {var h =;$(#section-637).append(h);} });

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册