WIKI使用導(dǎo)航
站長(zhǎng)百科導(dǎo)航
站長(zhǎng)專(zhuān)題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢(qián)
- 虛擬主機(jī)
- cPanel
- 網(wǎng)址導(dǎo)航專(zhuān)題
- 云計(jì)算
- 微博營(yíng)銷(xiāo)
- 虛擬主機(jī)管理系統(tǒng)
- 開(kāi)放平臺(tái)
- WIKI程序與應(yīng)用
- 美國(guó)十大主機(jī)
WordPress: Creating Options Pages:修訂間差異
(新頁(yè)面: == Introduction == Creating custom options panels in WordPress is relatively easy. Firstly, to create the menu item and the new page, see WordPress:Adding Administration Menus. So ...) ? |
無(wú)編輯摘要 ? |
||
第1行: | 第1行: | ||
== Introduction == | == Introduction == | ||
== 介紹 == | |||
Creating custom options panels in WordPress is relatively easy. | Creating custom options panels in WordPress is relatively easy. | ||
在WordPress中創(chuàng)建自定義選項(xiàng)面板,較為簡(jiǎn)單。 | |||
Firstly, to create the menu item and the new page, see [[WordPress:Adding Administration Menus]]. | Firstly, to create the menu item and the new page, see [[WordPress:Adding Administration Menus]]. | ||
首先,請(qǐng)看看[[WordPress:Adding Administration Menus|添加管理菜單]],創(chuàng)建菜單內(nèi)容和新的頁(yè)面。 | |||
So long as you stick to this structure, WordPress will handle all of the option creation, update, saving, and redirection for you. It will check permissions, and do all that other magic behind the scenes. | So long as you stick to this structure, WordPress will handle all of the option creation, update, saving, and redirection for you. It will check permissions, and do all that other magic behind the scenes. | ||
只要你遵循這個(gè)結(jié)構(gòu),WordPress會(huì)處理所有的選項(xiàng)創(chuàng)建,更新,保存和更改的內(nèi)容。WordPress會(huì)檢查權(quán)限,并且在幕后操作進(jìn)行許多其它神奇的操作。 | |||
== Form Tag == | == Form Tag == | ||
== 表格標(biāo)簽 == | |||
Once you have your page, you need to create an HTML form. Use this code: | Once you have your page, you need to create an HTML form. Use this code: | ||
創(chuàng)建了網(wǎng)頁(yè)后,你就需要?jiǎng)?chuàng)建HTML表格。使用這個(gè)代碼: | |||
? <form method="post" action="options.php"> | ? <form method="post" action="options.php"> | ||
<form method="post" action="options.php"> | |||
== nonce Magic == | |||
== nonce Magic == | == nonce Magic == | ||
第16行: | 第33行: | ||
Then after the opening form tag, insert this PHP code: | Then after the opening form tag, insert this PHP code: | ||
? <?php wp_nonce_field('update-options'); ?> | ? <?php wp_nonce_field('update-options'); ?> | ||
打開(kāi)表格標(biāo)簽后,插入這個(gè)PHP代碼: | |||
<?php wp_nonce_field('update-options'); ?> | |||
This will insert two hidden fields which automatically help to check that the user can update options and also redirect the user back to the correct admin page (because the form action is a different page). | This will insert two hidden fields which automatically help to check that the user can update options and also redirect the user back to the correct admin page (because the form action is a different page). | ||
這樣會(huì)插入兩個(gè)隱藏的欄,可以自動(dòng)地幫助核對(duì),用戶(hù)可以更新選項(xiàng),也可以使用戶(hù)返回到當(dāng)前的管理頁(yè)面(因?yàn)閒orm action是個(gè)不同的頁(yè)面)。 | |||
== Update Options Button == | == Update Options Button == | ||
== 更新選項(xiàng)按鈕 == | |||
At this point you may choose to insert the standard Update Options button, the HTML for which is: | At this point you may choose to insert the standard Update Options button, the HTML for which is: | ||
這時(shí),你可以選擇插入標(biāo)準(zhǔn)的更新選項(xiàng)按鈕,HTML是: | |||
? <p class="submit"> | ? <p class="submit"> | ||
<input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" /> | |||
</p> | |||
<p class="submit"> | |||
? <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" /> | ? <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" /> | ||
? </p> | ? </p> | ||
Note the use of the _e() function to handle translation of the text, see [[WordPress:Localizing WordPress]] for more info. | Note the use of the _e() function to handle translation of the text, see [[WordPress:Localizing WordPress]] for more info. | ||
注意使用the _e() function處理文本翻譯,更多的信息,請(qǐng)看看[[WordPress:Localizing WordPress|WordPress本地化]]。 | |||
== Field Names == | == Field Names == | ||
== Field 名稱(chēng) == | |||
Use fields with the same names that you want your newly created options (stored in the options table) to be called, for example: | Use fields with the same names that you want your newly created options (stored in the options table) to be called, for example: | ||
使用欄的名稱(chēng),與你希望最新創(chuàng)建的選項(xiàng)(儲(chǔ)存在選項(xiàng)表格中)得到調(diào)用的名稱(chēng)相同,例如: | |||
? <input type="text" name="new_option_name" value="<?php echo get_option('new_option_name'); ?>" /> | ? <input type="text" name="new_option_name" value="<?php echo get_option('new_option_name'); ?>" /> | ||
<input type="text" name="new_option_name" value="<?php echo get_option('new_option_name'); ?>" /> | |||
Note that by using the get_option() function as the value for the field, this will automatically be updated when the options are saved. | Note that by using the get_option() function as the value for the field, this will automatically be updated when the options are saved. | ||
注意通過(guò)使用get_option()函數(shù)作為欄的參數(shù)值,選項(xiàng)保存的時(shí)候,這會(huì)自動(dòng)更新。 | |||
== action Field == | |||
== action Field == | == action Field == | ||
第39行: | 第86行: | ||
Next, create a hidden field called action containing the value update. | Next, create a hidden field called action containing the value update. | ||
? <input type="hidden" name="action" value="update" /> | ? <input type="hidden" name="action" value="update" /> | ||
其次,創(chuàng)建創(chuàng)建隱藏的欄called action,包含更新的參數(shù)值。 | |||
<input type="hidden" name="action" value="update" /> | |||
== page_options Field == | |||
== page_options Field == | == page_options Field == | ||
Finally, create a hidden field called page_options containing a comma separated list of all the options in the page that should be written on save. | Finally, create a hidden field called page_options containing a comma separated list of all the options in the page that should be written on save. | ||
最后,創(chuàng)建包含用逗號(hào)分開(kāi)的網(wǎng)頁(yè)中所有選項(xiàng)的列表,稱(chēng)為page_options,隱藏的field,編寫(xiě)這些網(wǎng)頁(yè)時(shí),應(yīng)該保存。 | |||
? <input type="hidden" name="page_options" value="new_option_name,some_other_option,option_etc" /> | ? <input type="hidden" name="page_options" value="new_option_name,some_other_option,option_etc" /> | ||
<input type="hidden" name="page_options" value="new_option_name,some_other_option,option_etc" /> | |||
== Closing Tags == | == Closing Tags == | ||
== 關(guān)閉標(biāo)簽== | |||
Then obviously close the form tag after your other options, and if you like, include another "Update Options" button, this is the WordPress default. | Then obviously close the form tag after your other options, and if you like, include another "Update Options" button, this is the WordPress default. | ||
接著,很明顯,在你的其它選項(xiàng)之后,關(guān)閉表格標(biāo)簽,如果你愿意,可以加上另一個(gè)"更新選項(xiàng)"按鈕,這個(gè)按鈕是WordPress默認(rèn)帶有的。 | |||
? <p class="submit"> | ? <p class="submit"> | ||
<input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" /> | |||
</p> | |||
</form> | |||
<p class="submit"> | |||
? <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" /> | ? <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" /> | ||
? </p> | ? </p> | ||
? </form> | ? </form> |
2008年9月3日 (三) 09:28的最新版本
Introduction[ ]
介紹[ ]
Creating custom options panels in WordPress is relatively easy.
在WordPress中創(chuàng)建自定義選項(xiàng)面板,較為簡(jiǎn)單。
Firstly, to create the menu item and the new page, see WordPress:Adding Administration Menus.
首先,請(qǐng)看看添加管理菜單,創(chuàng)建菜單內(nèi)容和新的頁(yè)面。
So long as you stick to this structure, WordPress will handle all of the option creation, update, saving, and redirection for you. It will check permissions, and do all that other magic behind the scenes.
只要你遵循這個(gè)結(jié)構(gòu),WordPress會(huì)處理所有的選項(xiàng)創(chuàng)建,更新,保存和更改的內(nèi)容。WordPress會(huì)檢查權(quán)限,并且在幕后操作進(jìn)行許多其它神奇的操作。
Form Tag[ ]
表格標(biāo)簽[ ]
Once you have your page, you need to create an HTML form. Use this code:
創(chuàng)建了網(wǎng)頁(yè)后,你就需要?jiǎng)?chuàng)建HTML表格。使用這個(gè)代碼:
<form method="post" action="options.php">
<form method="post" action="options.php">
nonce Magic[ ]
nonce Magic[ ]
Then after the opening form tag, insert this PHP code:
<?php wp_nonce_field('update-options'); ?>
打開(kāi)表格標(biāo)簽后,插入這個(gè)PHP代碼:
<?php wp_nonce_field('update-options'); ?>
This will insert two hidden fields which automatically help to check that the user can update options and also redirect the user back to the correct admin page (because the form action is a different page).
這樣會(huì)插入兩個(gè)隱藏的欄,可以自動(dòng)地幫助核對(duì),用戶(hù)可以更新選項(xiàng),也可以使用戶(hù)返回到當(dāng)前的管理頁(yè)面(因?yàn)閒orm action是個(gè)不同的頁(yè)面)。
Update Options Button[ ]
更新選項(xiàng)按鈕[ ]
At this point you may choose to insert the standard Update Options button, the HTML for which is:
這時(shí),你可以選擇插入標(biāo)準(zhǔn)的更新選項(xiàng)按鈕,HTML是:
<p class="submit"> <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
Note the use of the _e() function to handle translation of the text, see WordPress:Localizing WordPress for more info.
注意使用the _e() function處理文本翻譯,更多的信息,請(qǐng)看看WordPress本地化。
Field Names[ ]
Field 名稱(chēng)[ ]
Use fields with the same names that you want your newly created options (stored in the options table) to be called, for example:
使用欄的名稱(chēng),與你希望最新創(chuàng)建的選項(xiàng)(儲(chǔ)存在選項(xiàng)表格中)得到調(diào)用的名稱(chēng)相同,例如:
<input type="text" name="new_option_name" value="<?php echo get_option('new_option_name'); ?>" />
<input type="text" name="new_option_name" value="<?php echo get_option('new_option_name'); ?>" />
Note that by using the get_option() function as the value for the field, this will automatically be updated when the options are saved.
注意通過(guò)使用get_option()函數(shù)作為欄的參數(shù)值,選項(xiàng)保存的時(shí)候,這會(huì)自動(dòng)更新。
action Field[ ]
action Field[ ]
Next, create a hidden field called action containing the value update.
<input type="hidden" name="action" value="update" />
其次,創(chuàng)建創(chuàng)建隱藏的欄called action,包含更新的參數(shù)值。 <input type="hidden" name="action" value="update" />
page_options Field[ ]
page_options Field[ ]
Finally, create a hidden field called page_options containing a comma separated list of all the options in the page that should be written on save.
最后,創(chuàng)建包含用逗號(hào)分開(kāi)的網(wǎng)頁(yè)中所有選項(xiàng)的列表,稱(chēng)為page_options,隱藏的field,編寫(xiě)這些網(wǎng)頁(yè)時(shí),應(yīng)該保存。
<input type="hidden" name="page_options" value="new_option_name,some_other_option,option_etc" />
<input type="hidden" name="page_options" value="new_option_name,some_other_option,option_etc" />
Closing Tags[ ]
關(guān)閉標(biāo)簽[ ]
Then obviously close the form tag after your other options, and if you like, include another "Update Options" button, this is the WordPress default.
接著,很明顯,在你的其它選項(xiàng)之后,關(guān)閉表格標(biāo)簽,如果你愿意,可以加上另一個(gè)"更新選項(xiàng)"按鈕,這個(gè)按鈕是WordPress默認(rèn)帶有的。
<p class="submit"> <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
</form>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
</form>