无需登陆FTP 新建一个wordpress主题文件
- 时间:2020-05-27 19:03:24
- 分类:网络文摘
- 阅读:135 次
对于wordpress主题设计者而言,主题文件的效果测试是必不可少的。而每一个新建的主题文件,都必须通过FTP才能上传到主题文件夹下。现在有一个简单的方法,可以绕过FTP直接在wordpress主题文件夹下新建一个空白的主题PHP文件。之后,在线编辑这个PHP文件就可以测试代码效果了。具体操作如下:
PHP有一个叫做“touch”的命令,通过此命令,用户可以获得创建新的PHP文件的权限。假设你的主题目录为yourthemes,想要新建一个new.php文件,只需将下面的代码添加到当前主题的header.php文件中:
- <?php touch('wp-content/themes/yourthemes/new.php'); ?>
之后,保存header.php文件,会在主题目录下自动生成一个空白的new.php文件,如下图:

现在你可以在new.php中添加任意代码了。最后别忘了删除添加到header.php文件中的那行代码。
注:将wordpress模板代码分成更小的PHP文件,易于编辑和在模板中调用。想要在模板文件中调用新建的new.php文件,可以通过下面的代码:
- <?php get_template_part(' new '); ?>
原文:http://www.quickonlinetips.com/archives/2014/06/wordpress-theme-files-without-ftp
推荐阅读:Build Your First Node.JS Unikernel with OPS The Intersection Algorithm of Two Arrays using Hash Maps in C++/ What Businesses Would Be Like if Web Hosting Didn’t Exist? How to Find the Dominant Index in Array (Largest Number At Least K Closest Points to Origin Algorithm by using Priority Queues in Total Number of Ways to Decode the Message via Dynamic Programmi The License Key Formatting Algorithm in C++ Integrating LinkedIn Long-Form Posts in Your Blogging Strategy A Quick Guide on Beefing Up Your WordPress Security 10 Proven Ways to Destroy Writer’s Block
- 评论列表
-
- 添加评论