无需登陆FTP 新建一个wordpress主题文件

  • 时间:2020-05-27 19:03:24
  • 分类:网络文摘
  • 阅读:143 次

对于wordpress主题设计者而言,主题文件的效果测试是必不可少的。而每一个新建的主题文件,都必须通过FTP才能上传到主题文件夹下。现在有一个简单的方法,可以绕过FTP直接在wordpress主题文件夹下新建一个空白的主题PHP文件。之后,在线编辑这个PHP文件就可以测试代码效果了。具体操作如下:

PHP有一个叫做“touch”的命令,通过此命令,用户可以获得创建新的PHP文件的权限。假设你的主题目录为yourthemes,想要新建一个new.php文件,只需将下面的代码添加到当前主题的header.php文件中:

  1. <?php touch('wp-content/themes/yourthemes/new.php'); ?>

之后,保存header.php文件,会在主题目录下自动生成一个空白的new.php文件,如下图:

无需登陆FTP创建wordpress主题文件

现在你可以在new.php中添加任意代码了。最后别忘了删除添加到header.php文件中的那行代码。

注:将wordpress模板代码分成更小的PHP文件,易于编辑和在模板中调用。想要在模板文件中调用新建的new.php文件,可以通过下面的代码:

  1. <?php get_template_part(' new '); ?>

 

原文:http://www.quickonlinetips.com/archives/2014/06/wordpress-theme-files-without-ftp

推荐阅读:
3 Times Social Media and Cancel Culture Helped in Snuffing Out R  How to Track Your Time as a Freelance Blogger  US Government on Ban TikTok: Should you worry about your blog?  Blogging Mistakes Most Beginner Bloggers Make  Creating a Website for Your Brand: 4 Best Practices You Must Con  What Is Content and Why Does It Matter?  5 Things to Know When Starting a Financial Blog  How to Improve the Marketing for Your Online Business  Building an Online Store – What You Need to Do  Independent Digital Media Is Being Shut Down Around the World, a 
评论列表
添加评论