PHP - 包含具有特定ID的文件

时间:2016-06-13 18:31:37

标签: php mysql database plugins content-management-system

我制作了一个与“短代码”配合使用的自定义cms系统。有了一些帮助,我到目前为止,但我仍然坚持为特定ID制作短代码。有人可以指出我正确的方向或解释我如何做到这一点?

这就是我得到的:

/*
example of content stored in database:

$content = "These are my clothes in a slider [plugin-slider] , and these are my shoes [plugin-slider]";

what i would like to to:

$content = "These are my clothes in a slider [plugin-slider id=3] , and these are my shoes [plugin-slider id=5]";

or even better:

$content = "These are my clothes in a slider [plugin-slider name=clothes] , and these are my shoes [plugin-slider name=shoes]";
*/

<?php
    $regex = '~\[plugin-([^]]+)]~';
    $content = htmlspecialchars_decode($page['content']);//content from db
    $parts = preg_split($regex, $content, -1, PREG_SPLIT_DELIM_CAPTURE); //get shortcodes

    foreach($parts as $k => $v){
        if($k & 1)
            include_once('plugins/'.$v.'.php'); //include shortcodes
        else
            echo htmlspecialchars_decode($v); //rest of content
    }
?>

现在假设我有一个插件滑块,并为特定页面制作一个,但我想使用同一插件中的另一个滑块用于另一个页面。我可以通过ID包含它们吗?比如[plugin-slider id = 26]?

我几乎可以肯定我也需要编辑插件,但我不知道从哪里开始。感谢所有帮助!

0 个答案:

没有答案