以下は、あなたの(挿入 - 編集)ページに1追加のメタボックスを追加します。
カスタムフィールドを追加して保存することができます。
選択したテンプレートによっては切り替わりません。
これを行うには、javascriptを使用してフィールドを表示/非表示にすることをおすすめします。 <のIDに基づいて
可能なすべてのフィールドで動作するメタボックスが表示されたら、テンプレートに基づいて非表示にして表示するためのjavascriptのヘルプを表示できます。
GL
<?php
add_action('add_meta_boxes', 'carrousel_build');
function carrousel_build()
{
add_meta_box('carrousel', 'Carrousel opties', 'carrousel_options', 'page',/*show on 'pages'*/ 'normal', 'high');
}
//this will add a meta box with custom fields
function carrousel_options ($post)
{ ?>
<p>
Description
</p>
<p id="field1_container">
<label for="field1">Custom field 1</label>
<br/>
<input type="text" id="field1" name="field1" value="<?php echo get_post_meta($post->ID, 'field1', true) ?>" size="25" />
</p>
<p id="field2_container">
<label for="field2">Custom field 2</label>
<br/>
<input type="text" id="field2" name="field2" value="<?php echo get_post_meta($post->ID, 'field2', true) ?>" size="25" />
</p>
<?php }
//save the values of the meta box
add_action('save_post', 'post_save');
function post_save($post_id)
{
// Check permissions
if (isset ($_POST['post_type']) && 'carrousel' == $_POST['post_type'] && !current_user_can('edit_page', $post_id))
{
return;
}
if (isset($_POST['field1'])) {
$subtitle = $_POST['field1'];
update_post_meta($post_id, 'field1', $subtitle);
}
if (isset($_POST['field2']))
{
$link = $_POST['field2'];
update_post_meta($post_id, 'field2', $link);
}
}
は、あなたがこれらのフィールドには、フロントエンドで満たされたか、管理者がその値がフロントエンドに表示され、それらを埋めていますか?したいですか – janw
管理者はWordPress管理領域の値を入力します。私は、作成/編集中のテンプレートに基づいて利用可能なフィールドを自動的に表示するテンプレートが好きです。 – StephenPAdams