Ich möchte ein neues Einstellungsfeld auf der Seite Post hinzufügen. Ich möchte in der Kategorie oder darüber sein, wie folgt:
Sie müssen die Funktion add_meta_box
verwenden
add_action( 'add_meta_boxes', 'my_custom_meta_box' ) );
function my_custom_meta_box(){
$args = array();
add_meta_box(
'my_metabox_id',
__( 'My Meta Box', 'my_textdomain' ), // Title
'my_callback_function', // Callback function that renders the content of the meta box
'post', // Admin page (or post type) to show the meta box on
'side', // Context where the box is shown on the page
'high', // Priority within that context
$args // Arguments to pass the callback function, if any
);
}
function my_callback_function( $args ){
//The markup for your meta box goes here
}
Fügen Sie den folgenden Code in Ihre function.php
-Datei ein. Mit dem folgenden Code wird ein Textfeld im Post-Typ "Post" erstellt. Nur das Definieren von Textfeldern funktioniert nicht. Sie müssen es auch speichern, wenn der Beitrag gespeichert wird. Überprüfen Sie die URL unten, um den Wert der Meta-Box zu speichern.
add_action( 'add_meta_boxes', 'cd_meta_box_add' );
function cd_meta_box_add(){
add_meta_box( 'my-meta-box-id', 'My First Meta Box', 'cd_meta_box_cb', 'post', 'normal', 'high' );}
function cd_meta_box_cb(){
<label for="my_meta_box_text">Text Label</label>
<input type="text" name="my_meta_box_text" id="my_meta_box_text" />
}
Weitere Informationen finden Sie unter http://code.tutsplus.com/tutorials/how-to-create-custom-wordpress-writemeta-boxes--wp-20336