WordPress:Editing Files

来自站长百科
Seadragon530讨论 | 贡献2008年4月8日 (二) 17:43的版本
跳转至: 导航、​ 搜索

There are times when you will need to edit the WordPress files, especially if you want to make changes in your WordPress Theme. WordPress features two built-in editors for editing files from within your browser while online: [[Wordpress:#Using the File Editor|The File Editor]] and [[Wordpress:#Using the Theme Editor|The Theme Editor]]. You can also edit files copied or stored on your computer and then upload them to your site using an FTP client.

你可能有很多次需要编辑WordPress文件,特别是如果你想要对你的WordPress 主题做出更改时。WordPress有2个内建的编辑器可以在线时在浏览器内编辑文件:[[Wordpress:#Using the File Editor|文件编辑器]]和[[Wordpress:#Using the Theme Editor|主题编辑器]]。你也可以编辑复制过来的或者存储在你电脑上的文件,然后使用FTP 客户端上传到你的网站。

Before editing any of your WordPress files, check the following:

在开始编辑WordPress文件之前,请检查如下内容:

BACKUP! And Work from Backups
Work from copies of backup files when possible and/or make sure that you backup your information frequently as you work and make changes. Keep backups in a safe place.
备份!使用备份来操作
如果可能的话使用复件或备份文件操作,或者确定你会在做出更改后时常备份你的信息。把备份放在安全的地方。
File Permissions
When working online, to modify the files they have to be set for the appropriate file permissions to allow modifications. If you see a note at the bottom of the WordPress Built-in Editor panel that says "If this file was writable you could edit it.", this means you need to change the file permissions before you can make changes to the file.
文件许可
当在线操作时,为了修改文件,你不得不为文件许可做出适当的设置以允许修改。如果你看到了WordPress内建编辑器面板的底部的注释"如果本文件可写,就可以进行编辑.",这意思是说你对某文件做出更改的时候需要改变文件的许可。
Use a Text Editor to Edit Files
If you will be making changes to files outside of the built-in File Editor, use a text editor. DO NOT USE A WORD PROCESSING PROGRAM. Word processors change the quote marks to characters and may convert other characters or bring in unwanted code which will cause the file to break when used. There are also some HTML generator programs that should not be used for similar reasons.
使用 文字编辑器 来编辑文件
如果你要使用外部编辑器对文件做出更改,就用文字编辑器。不要使用字处理程序.字处理程序改变标点符号,还有可能改变字体或者带来一些不想要的代码,这些都有可能导致文件使用时崩溃。因为这个原因,还有些HTML自动生成程序也不宜使用。

Using the File Editor

WordPress contains a built-in editor to allow editing files directly from within your browser while online. It is called the File Editor.

使用文件编辑器

WordPress包含了一个内建的编辑器,允许在线时在浏览器内直接编辑文件。叫做文件编辑器

Access the built-in File Editor from the Administration > Manage > Files Panel.

管理 > 操作 > 文件面板进入内建编辑器。

  • To view a file in the File Editor, click on the file from the list or type in the specific address such as example.com/wordpress/filename.php
    • If the file is "writable" (allowed to be changed), you will see a button at the bottom of the editing window that says Update File. Click this when you are done with your edits and ready to save the file.
    • If the file is not "writable", you will see a note under the bottom of the editing window saying the file is not writable. You will need to CHMOD the file to 666 in order to make it writable through an FTP program (preferably FileZilla) before you can edit it.
  • Before editing, backup your file by saving a copy!
  • Inside the File Editor window, you may make changes to the file. Edit with care as to not delete or harm the code inside the file.
  • When ready to save the file, click the Update File button at the bottom. This will save the file.
  • 想在文件编辑器中查看文件, 点击列表中的文件,或者输入详细地址,如 example.com/wordpress/filename.php
    • 如果文件"可写" (允许更改), 你会在编辑窗口底部看到一个按钮,写着更新文件。 当你完成更改后,点击它,准备保存文件。
    • 如果文件"不可写", 你会看见编辑窗口底部有一个注释,说明该文件不可写。你需要通过一个FTP程序(推荐 FileZilla)对文件进行CHMOD操作,改为666以把文件变为可写状态。
  • 编辑之前,把你的文件进行备份!'
  • 在文件编辑器窗口里,你可以对文件进行改动。编辑的时候要小心,不要把一些文件内部的代码删除或者损坏。
  • 准备保存文件时,点击底部的更新文件按钮。文件就被保存了。

Using the Theme Editor

WordPress contains a built-in editor that allows you to edit Theme files directly from within your browser. It is called the Theme Editor.

使用主题编辑器

WordPress包含了一个内建的编辑器,允许直接从浏览器编辑编辑主题文件。叫做主题编辑器

Access the Theme Editor from the Administration > Presentation > Theme Editor Panel.

管理 > 界面 > 主题编辑器面板进入主题编辑器

To view a file in the Theme Editor, click on the file from the list.

点击列表中的文件可以在主题编辑器中查看文件。

More information on editing themes is available at Wordpress:Theme Development and Wordpress:Using Themes

有关编辑主题的更多信息可以在主题开发使用主题中找到。

Editing Files Offline

To edit files offline on your computer, you can use any text editor, open the file and make changes. Again, be sure the original file is backed up!

脱机编辑文件

想要在你的电脑上脱机编辑文件,可以使用任何文字编辑器,打开文件做出改动。当然要确定你的原文件已经备份。

If you will be changing any core WordPress files, take notes and store them in a text file in your WordPress root directory and make a backup copy of them for future reference and upgrades.

如果你准备改动任何核心WordPress文件,做个记录并把它们用文本文件保存在你的WordPress根目录下,做出备份,以便将来参考和更新。

After saving the file, upload it to the appropriate folder on your WordPress site using an FTP client. Then view the results in your browser to check if the desired change has taken effect.

保存文件之后,使用FTP客户端上传到相应的WordPress网页文件夹中。然后在你的浏览器中查看结果,看是否想要的更改已经生效。

What Files Can Be Edited?

From within the WordPress Built-in Editor, the following file types may be edited, if writable:

  • HTML
  • PHP
  • CSS
  • .htaccess
  • TXT (and related text-like files such as RTF)

什么文件可以被编辑?

通过使用WordPress内部编辑器,在可写状态下,以下几种文件格式可以编辑:

  • HTML
  • PHP
  • CSS
  • .htaccess
  • TXT (相关的类似文本的文件如 RTF)

Things You Need to Know

File Permissions
To edit a file through the Built-in Editor, the permissions for that file must be set to 666. You can change the permissions on files by using a FTP client program, web-based interface provided by your host, or from the command-line using telnet or ssh (secure shell). These options are dependent on the type of access your host offers.
Instant Changes
The changes you make in the WordPress editors are instant and you do not need an FTP client program. You are changing the files online. You and visitors will see the changes immediately.

须知

文件许可
要通过内建文件编辑器编辑文件,该文件的许可必须设置为666。你可以通过FTP 客户端程序、你的主机提供的基于网络的操作界面、使用telnet或者ssh (secure shell) 的命令行 更改许可。这些操作取决于你的主机提供什么类型的访问通路。
即时更改
你在WordPress编辑器中所做出的更改是即时的,你不需要使用FTP客户端程序。你是在线更改文件。你和访问者可以立即看到更改结果。
Make a Mistake? Use the Backup Files
Backup all files before editing. If you make a mistake, copy the file back onto your site from the backed up files. No backup? You will need to download WordPress, your Theme, and whatever files you need to replace and start over. BACKUP FIRST.
出错了? 使用备份文件
编辑之前备份所有的文件。如果你出了什么错误,把备份文件复制回来。没有备份?你就需要重新下载WordPress、主题、和其他你需要替换的文件然后重头再来。首先备份。
Make a Bigger Mistake? Delete
If the changes you make cause your site to "crash" or gives you a blank screen or screen filled with errors, if you cannot access your Administration Panels, delete the changed file and replace it with a good one from your backup.

出了更大的错误? 删除:如果你做出的改动导致你的网页"崩溃"了、给出空白页或者页面到处都是错误,如果你不能进入管理面板,删除改动过的文件然后用一个备份中正常的文件替换它。

Use Cautions With These Editors

DO NOT use these for editing your WordPress files at all, ever, really, DON'T:

  • Microsoft Word
  • WordPerfect
  • ANY word-processor
  • Microsoft Publisher
  • ANY Do-It-Yourself Instant Web Page Software

使用这些编辑器的警告

不要使用以下这些软件编辑WordPress文件,实在不要用:

  • Microsoft Word
  • WordPerfect
  • 任何字处理软件
  • Microsoft Publisher
  • 任何可以自定义即时网页的软件

Use these only if you are very familiar with them:

  • Dreamweaver - it's best to copy from the WordPress editor, replacing what Dreamweaver puts in new files by default.
  • FrontPage - watch out for extra code inserted by FrontPage, and don't try to use its built-in templates ... also watch for IE-specific code which can make your site look or act unexpectedly in certain browsers, which you want to stay away from, because you want your website to be viewable in ALL browsers possible, so make sure you take out the IE-specific code, or else your blog will be doomed to failure. So, just watch out all the time for all IE-specific code, and DELETE it immediately, or else your blog will be dooomed to failure.

当你对他们非常熟悉的时候可以使用以下软件:

  • Dreamweaver – 最好从WordPress 编辑器中复制出来,覆盖默认情况下Dreamweaver在新文件中的内容
  • FrontPage – 注意FrontPage 插入的多余的代码,不要试着使用它的内置模板…同时注意一些IE特效代码,可能会造成你的页面在某些特定浏览器中非正常显示,你肯定不想这样,因为你希望在所有浏览器中都可以正常浏览,所以务必确认已经排除了IE特效代码,否则你的blog注定要失败。所以,必须一直保持谨慎,及时删除IE特效代码。

Recommended editors are listed at the Text Editor Section of the Glossary

推荐编辑器在术语表的文字编辑器部分有列出。

This article is [[WordPress::Category:Copyedits|marked]] as in need of editing. You can help Codex by editing it.