Typecho在文章中插入广告代码

折腾博客

温馨提示:这篇文章已超过1175天没有更新,请注意相关的内容是否还可用!

Typecho在文章中插入广告代码,其实就是判断查找文章的第一个p,然后,插入代码,放到functions里使用即可。

function themeInit($archive) {

// 判断是否是文章,如果是就插入广告
$ad_code = '
这是你的广告
'; if ($archive->is('single')) { $archive->content = prefix_insert_after_paragraph( $ad_code, 2, $archive->content );; } } // 插入广告所需的功能代码 function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) { $closing_p = '

'; $paragraphs = explode( $closing_p, $content ); foreach ($paragraphs as $index => $paragraph) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; } if ( $paragraph_id == $index + 1 ) { $paragraphs[$index] .= $insertion; } } return implode( '', $paragraphs ); }
文章版权声明:除非注明,否则均为折腾博客原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog
验证码
评论列表 (暂无评论,24人围观)

还没有评论,来说两句吧...

取消
微信二维码
微信二维码
支付宝二维码