2015-05-29 64 views
-1

插件創建的大多數情況以及元框的代碼。它的代碼非常冗長,無法通過插件激活訪問metabox。每個站點的插件數量會降低站點的性能。請幫助下面的代碼如何在wordpress中創建一個自定義metabox而無需創建插件?

+0

插件或主題是唯一的方法,除非你想修改實際的wordpress代碼,我不會推薦。 – Sirko

+0

現在我明白了wordpress編碼的標準和方法..我們可以在插件的幫助下創建任何東西,否則我們可以直接將代碼添加到'function.php'中。但最好的方法是編寫插件,而不是修改核心文件。感謝您的幫助 –

回答

4

粘貼到Word中press.it您的活動主題function.php將創建自定義的元框:

/*Create custom MetaBox*/ 
function CreateTextfield() 
{ 
$screen = 'post'; 
add_meta_box('my-meta-box-id','Text Editor','displayeditor',$screen,'normal','high'); 
} 
add_action('add_meta_boxes', 'CreateTextfield') ; 

/*Display PostMeta*/ 
function displayeditor($post) 
{ 
global $wbdb; 
$metaeditor = 'metaeditor'; 
$displayeditortext = get_post_meta($post->ID,$metaeditor, true); 
?> 
<h2>Secound Editor</h2> 
<label for="my_meta_box_text">Text Label</label> 
    <input type="text" name="my_meta_box_text" id="my_meta_box_text" value="<?php echo $displayeditortext;?>" /> 
    <?php   
} 

/*Save Post Meta*/ 
function saveshorttexteditor($post) 
{ 
$editor = $_POST['my_meta_box_text']; 
update_post_meta( $post, 'metaeditor', $editor); 
} 
add_action('save_post','saveshorttexteditor'); 

您可以創建並通過下面的代碼更新postmeta。你可以通過在$ screen中創建數組來添加屏幕。

+0

謝謝..明白了:) –

+0

你會介意接受答案,如果它的有用和工作的例子你.. :) –

相關問題