Codex

zh-cn:编辑文件

Contents

有时您需要编辑 WordPress 文件,比如您需要对您的 WordPress 主题做出一些改动。WordPress 的特色是带有一个内置的编辑器,可以直接在浏览器中进行快速编辑:主题编辑器。您也可以先在本地编辑文件的副本,然后再使用 FTP 客户端进行上传。

本文已被标记为未完成状态。您可以将其补充或翻译完整,以此帮助完善 Codex。

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

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, you need to set the appropriate file permissions to modify and save them. 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 any changes.
Use a Text Editor to Edit Files 
To make changes to files outside of the built-in Plugin or Theme 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; these changes will cause the file to break. There are also some HTML generator programs that should not be used for similar reasons.

Using the Theme Editor and Plugin Editor

WordPress contains two built-in editors that allows you to edit Theme files directly from within your browser. They are called the Theme Editor and Plugin Editor.

Access the Theme Editor from the Administration > Appearance > Editor menu.

The Plugin Editor is located at Administration > Plugins > Editor.

To view a file in these editors, click on the file from the left-hand side list.

More information on editing themes is available at Theme Development and Using Themes.. You can learn more about editing plugins at Writing a Plugin and Plugin Resources.

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)

Things You Need to Know

SEARCH 
There isn't any. There isn't any REPLACE either. You just have to scroll through the file to find what you are looking for. Alternatively you can use an external editor. There are not any line numbers either, so if you are using Firebug to play with your layout, you just have to guess what line you're on in the Theme Editor.
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.
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.
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.

Editing Files Offline

To edit files offline, you must can use any of the recommended text editors to create and edit files and an FTP client to upload them. Make sure to view the results in your browser to check if the desired change has taken effect.

Note: It is not recommended to change core WordPress files other than wp-config.php. If you must change anything else, 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.

Using Text Editors

Editors to Avoid

If you use any external editor that is not a text-only editor, such as standard word-processing software, it can corrupt the file you are editing.

Editors to avoid using to create and edit files include:

  • Microsoft Word
  • WordPerfect
  • OpenOffice
  • Apple iWork Pages
  • Microsoft Publisher
  • Microsoft Works
  • Microsoft Excel
  • Adobe Photoshop
  • Adobe Illustrator
  • Adobe Dreamweaver
  • Any do-it-yourself instant web page software.

If you must use Adobe Dreamweaver or Microsoft FrontPage, keep these guidelines in mind:

  • Adobe Dreamweaver: To make sure your files work properly, copy your content from the WordPress editor and replace what Dreamweaver puts in new files by default.
  • Microsoft FrontPage: Be vigilant of extra code inserted by FrontPage, and don't try to use its built-in templates. Also, watch for Internet Explorer specific code because it can make your site look or act unexpectedly in certain browsers, which should be avoided.

Acceptable Editors

The Text Editor Section of the Glossary recommends the following editors:

  • BBEdit
  • Boxer Text Editor
  • Coda
  • Crimson Editor
  • EditPad
  • EditPlus
  • Editra
  • emacs
  • Fraise
  • gedit
  • JEdit
  • Kate
  • Komodo Edit
  • Kwrite
  • Notepad++
  • phpDesigner
  • pico
  • PSPad
  • Smultron
  • SubEthaEdit
  • TextEdit
  • TextMate
  • TextPad
  • TextWrangler
  • UltraEdit-32
  • vim
  • Notepad2 (Windows, Freeware)
  • WebTide Editor.
本文已被标记为需要加工。欢迎您踊跃编辑,来帮助 Codex。