为wordpress增加function模板应用-以后不用修改模板函数添加扩展功能

作者:matrix 被围观: 7,748 次 发布时间:2013-08-09 分类:Wordpress 兼容并蓄 | 2 条评论 »

这是一个创建于 3911 天前的主题,其中的信息可能已经有所发展或是发生改变。

以前在“ 更换主题-七彩之家BLUE2.0以及后续的修改 ”中的functions.php添加了很多内容,稍微有点差池就导致WordPress无法打开。

为wordpress增加function模板应用

幸好WordPress很人性化的支持无限扩展-include all php script功能,可以实现更自由的添加自定义功能,避免了直接修改模板函数functions.php导致的各类风险~

步骤1.实现方法很简单,在functions.php中添加代码:

//增加function模板应用include all PHP script 以后不用再次添加内容  
define('theme_apps', TEMPLATEPATH.'/apps');//在此定义存放php文件的文件夹名称  
IncludeAll( theme_apps );  
function IncludeAll($dir){  
    $dir = realpath($dir);  
    if($dir){  
        $files = scandir($dir);  
        sort($files);  
        foreach($files as $file){  
            if($file == '.' || $file == '..'){  
                continue;  
            }elseif(preg_match('/.php$/i', $file)){  
                include_once $dir.'/'.$file;  
            }  
        }//end foreach  
    }//end if  
}  
// -- 2013-8-8 1:39 END --------------------------------------  

2.之后在主题目录内新建apps文件夹,用来存放添加自定义功能的php文件。apps目录内的php文件可以随便命名,这样也就方便管理不用再修改模板函数文件。只是需要在文件头和尾各添加<?php和 ?>标签。

参考:http://www.oome.org/WordPress-theme-function-file.html

其他文章:
本文固定链接:https://www.hhtjim.com/to-increase-the-function-template-wordpress.html
matrix
本文章由 matrix 于2013年08月09日发布在Wordpress, 兼容并蓄分类下,目前没有通告,你可以至底部留下评论。
转载请注明:为wordpress增加function模板应用-以后不用修改模板函数添加扩展功能-HHTjim'S 部落格
关键字:,

有2 条评论 »

  1. 黑枸杞种苗 黑枸杞种苗 2013-8-9 13:59:47 +0800#1

    黑枸杞种苗http://www.heigouqi.cn Q171565-8817,您好,能友情链接吗

    • Matrix Matrix Moderator 2013-8-9 14:05:57 +0800

      好像咱的内容不怎么相关~ 希望找个博客的~

添加新评论 »

 🙈 😱 😂 😛 😭 😳 😀 😆 👿 😉 😯 😮 😕 😎 😐 😥 😡 😈 💡

插入图片

NOTICE: You should type some Chinese word (like “你好”) in your comment to pass the spam-check, thanks for your patience!