我將每個頁面內容分解爲內容類別,例如:概覽,產品詳細信息和課程/材料。所有在WP中的一個頁面/文章。在WP模板的左側邊欄/主體/右側邊欄中顯示Page數據片段
我想在主體中顯示概覽數據,在左邊欄中顯示產品詳細信息,在右邊欄中顯示課程/材料。
我該如何去做這件事,我已經在網上搜索,但沒有找到具體的東西。
任何建議將是最有幫助的。
我將每個頁面內容分解爲內容類別,例如:概覽,產品詳細信息和課程/材料。所有在WP中的一個頁面/文章。在WP模板的左側邊欄/主體/右側邊欄中顯示Page數據片段
我想在主體中顯示概覽數據,在左邊欄中顯示產品詳細信息,在右邊欄中顯示課程/材料。
我該如何去做這件事,我已經在網上搜索,但沒有找到具體的東西。
任何建議將是最有幫助的。
如果我處於您的情況,我會考慮將自己的「部分」存儲在自定義字段中。我可能會提供幫助,但是能否提供到目前爲止的鏈接?
編輯
我想自定義元領域將是最好的選擇,所以我創建了一個輕量級的插件,它會添加metaboxes到您的網頁,存儲數據的概述,產品細節,以及課程/材料。
下面就以插件的鏈接MediaFire
更新日誌
要調用在你的主題中的細節,您可以使用以下功能:
<?php get_content_overview($id) ?>
或
<?php echo (get_post_meta($id, 'get_content_overview', TRUE)) ?>
//獲取從 '概覽' meta框的細節
<?php get_content_details($id) ?>
或
<?php echo (get_post_meta($id, 'get_content_details', TRUE)) ?>
//獲取從 '詳細資料' meta框的細節
<?php get_content_supplements($id) ?>
或
<?php echo (get_post_meta($id, 'get_content_supplements', TRUE)) ?>
//獲取從 '課程/材料' 元包
插入Widget的詳細信息在側邊欄中,只有正在查看的網頁具有指定的元內容時,它們纔會顯示。
這裏是原始代碼(來自v1。0):
<?php
/*
Plugin Name: Content Meta Boxes (MB)
Plugin URI: http://mechabyte.com
Description: Displays custom content meta boxes.
Author: Matthew Smith
Version: 1.0
Author URI: http://mechabyte.com
*/
function get_content_overview() {
if (get_post_meta($post->ID, 'get_content_overview', TRUE)) {
echo get_post_meta($post->ID, 'get_content_overview', TRUE);
}
}
function get_content_details() {
if (get_post_meta($post->ID, 'get_content_details', TRUE)) {
echo get_post_meta($post->ID, 'get_content_details', TRUE);
}
}
function get_content_supplements() {
if (get_post_meta($post->ID, 'get_content_supplements', TRUE)) {
echo get_post_meta($post->ID, 'get_content_supplements', TRUE);
}
}
// Add the Meta Box
function add_content_boxes() {
add_meta_box(
'custom_meta_box', // $id
'Custom Content Boxes', // $title
'show_content_metabox', // $callback
'page', // $page
'normal', // $context
'high'); // $priority
}
add_action('add_meta_boxes', 'add_content_boxes');
// Field Array
$prefix = 'get_content';
$content_meta_fields = array(
array(
'label'=> 'Product Overview',
'desc' => 'Overview Data',
'id' => $prefix.'_overview',
'type' => 'textarea'
),
array(
'label'=> 'Product Details',
'desc' => 'Add some details about the product',
'id' => $prefix.'_details',
'type' => 'textarea'
),
array(
'label'=> 'Courses/Materials',
'desc' => 'Don\'t forget to add your courses and materials!',
'id' => $prefix.'_supplements',
'type' => 'textarea'
)
);
// The Callback
function show_content_metabox() {
global $content_meta_fields, $post;
// Use nonce for verification
echo '<input type="hidden" name="custom_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';
// Begin the field table and loop
echo '<table class="form-table">';
foreach ($content_meta_fields as $field) {
// get value of this field if it exists for this post
$meta = get_post_meta($post->ID, $field['id'], true);
// begin a table row with
echo '<tr>
<th><label for="'.$field['id'].'">'.$field['label'].'</label></th>
<td>';
switch($field['type']) {
// text
case 'text':
echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
<br /><span class="description">'.$field['desc'].'</span>';
break;
// checkbox
case 'checkbox':
echo '<input type="checkbox" name="'.$field['id'].'" id="'.$field['id'].'" ',$meta ? ' checked="checked"' : '','/>
<label for="'.$field['id'].'">'.$field['desc'].'</label>';
break;
// textarea
case 'textarea':
echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>
<br /><span class="description">'.$field['desc'].'</span>';
break;
} //end switch
echo '</td></tr>';
} // end foreach
echo '</table>'; // end table
}
// Save the Data
function save_content_meta($post_id) {
global $content_meta_fields;
// verify nonce
if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__)))
return $post_id;
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
// check permissions
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id))
return $post_id;
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
// loop through fields and save the data
foreach ($content_meta_fields as $field) {
$old = get_post_meta($post_id, $field['id'], true);
$new = $_POST[$field['id']];
if ($new && $new != $old) {
update_post_meta($post_id, $field['id'], $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
} // end foreach
}
add_action('save_post', 'save_content_meta');
?>
我沒有在目前這個公佈了仍處於dev的,我一直在尋找的自定義字段,但它好像你只能保存在那裏的數據有限。我可能需要每個「部分」大約需要1000個字符。 – Grant 2012-02-09 20:24:57
我的另一個想法是添加一些div ID,並嘗試將該數據以某種方式通過側邊欄。 – Grant 2012-02-09 20:25:46
我並非試圖淡化您的想法,但我認爲自定義字段將是一個更簡單的選項,並且在挖掘了一段時間之後,我找不到任何提及它們允許比文章本身更少的字符:P – Matt 2012-02-09 20:29:36