Typecho 实现短代码功能。

No Reply , Posted in 代码 on April 21, 2015

Typecho在functions.php 中实现类似wordpress短代码功能
typecho 实现短代码功能,同样是在 functions.php 中,但不是随意写。这里定义一个名为themeInit 模版初始方法,我们要实现什么样的功能,只需要在这里操作即可。例:

function themeInit($archive) {
    // $archive 在这里相当于我们模版中的 $this,具体可以打印看看
}

例如我在文章最后加入一句话,可以做如下操作:

function themeInit($archive) {
    $archive->content = addIntro($archive->content);
}

function addIntro($content) {
    $intro = '

我在这里

'; return $content . $intro; }

此文章转载自:https://github.com/shingchi/shingchi.github.com/issues/26

标签: 短代码