我正在wordpress 3.8上使用一个儿童主题“Twenty14”。在调试模式下,我会遇到以下关于小部件的错误。
注意:正在尝试获取\\wordpress\\wp content\\themes\\tema2014\\functions\\widgets中非对象的属性。php在线148
update_post_meta($post->ID, "_sidebar", $_POST["link"]);
以及
注意:未定义的索引:link in\\wordpress\\wp content\\themes\\tema2014\\functions\\widgets。php在线148
update_post_meta($post->ID, "_sidebar", $_POST["link"]);
以及
注意:未定义索引:\\u\\wordpress\\wp content\\themes\\tema2014\\functions\\widgets中的侧栏。php在线121
$link = $custom["_sidebar"][0];
这是完整的代码。
$dynamic_widget_areas = array (
\'sidebar-21\' => __( \'Page Specific Sidebar 1\', \'pietergoosen\' ),
\'sidebar-22\' => __( \'Page Specific Sidebar 2\', \'pietergoosen\' ),
\'sidebar-23\' => __( \'Page Specific Sidebar 3\', \'pietergoosen\' ),
\'sidebar-24\' => __( \'Page Specific Sidebar 4\', \'pietergoosen\' ),
\'sidebar-25\' => __( \'Page Specific Sidebar 5\', \'pietergoosen\' ),
\'sidebar-26\' => __( \'Page Specific Sidebar 6\', \'pietergoosen\' ),
\'sidebar-27\' => __( \'Page Specific Sidebar 7\', \'pietergoosen\' ),
\'sidebar-28\' => __( \'Page Specific Sidebar 8\', \'pietergoosen\' ),
\'sidebar-29\' => __( \'Page Specific Sidebar 9\', \'pietergoosen\' ),
\'sidebar-30\' => __( \'Page Specific Sidebar 10\', \'pietergoosen\' ),
);
foreach ( $dynamic_widget_areas as $id => $dynamic_widget_area ) {
register_sidebar(
array (
\'name\' => __( $dynamic_widget_area, \'pietergoosen\' ),
\'id\' => $id,
\'description\' => __( \'Page specific sidebars above the content sidebar\', \'pietergoosen\' ),
\'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</aside>\',
\'before_title\' => \'<h1 class="widget-title">\',
\'after_title\' => \'</h1>\',
));
}
}
add_action( \'widgets_init\', \'pietergoosen_widgets_init\' );
// Add dynamic sidebars
add_action(\'admin_init\', \'sidebar_init\');
add_action(\'save_post\', \'save_sidebar_link\');
function sidebar_init(){
add_meta_box("sidebar_meta", "Sidebar options", "sidebar_link", "page", "side", "default");
}
function sidebar_link(){
global $post, $dynamic_widget_areas;
$custom = get_post_custom($post->ID);
$link = $custom["_sidebar"][0];
?>
<div class="link_header">
<?
echo \'<select name="link" class="sidebar-selection">\';
echo \'<option>Choose Sidebar</option>\';
echo \'<option>No sidebars to choose from</option>\';
foreach ( $dynamic_widget_areas as $list ){
if($link == $list){
echo \'<option value="\'.$list.\'" selected="true">\'.$list.\'</option>\';
}else{
echo \'<option value="\'.$list.\'">\'.$list.\'</option>\';
}
}
echo \'</select><br />\';
?>
</div>
<p>Choose the sidebar to use with this page.</p>
<?php
}
function save_sidebar_link(){
global $post;
if (defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE) {return $post->ID;}
update_post_meta($post->ID, "_sidebar", $_POST["link"]);
}
add_action(\'admin_head\', \'sidebar_css\');
function sidebar_css() {
echo\'
<style type="text/css">
.sidebar-selection{width:100%;}
</style>
\';
}
有什么办法解决这个问题吗?