'widget_aside', 'description' => __('Display some page-related content in a sidebar')); $control_ops = array('width' => 400, 'height' => 350); $this->WP_Widget('aside', __('Aside'), $widget_ops, $control_ops); } function widget( $args, $instance ) { global $post; extract($args); if (!function_exists('widget_parse')) { function widget_parse($text) { ob_start(); eval('?>' . $text); $text = ob_get_contents(); ob_end_clean(); return($text); } } if (is_array($asides = get_post_meta($post->ID, 'aside'))) { foreach ($asides as $aside) { if (strlen($aside) > 0) { switch ($aside[0]) { case '#' : case '!' : $parts = explode(',', $aside); $prefix = ""; $suffix = ""; switch (count($parts)) { case 3 : $prefix = ($instance['parse'])?widget_parse($parts[1]):$parts[1]; $suffix = ($instance['parse'])?widget_parse($parts[2]):$parts[2]; case 1 : switch ($parts[0][0]) { case '#' : $id = substr($parts[0], 1); if ((ctype_digit($id)) && ($page = get_page($id))) { $aside = "

" . $page->post_title . "

" . wpautop($page->post_content); } else { $aside = "Aside: page " . $id . " not found"; } break; case '!' : $id = ((strlen($parts[0]) > 1) && ($parts[0][1] != '!'))?substr($parts[0], 1):substr($parts[0], 2); if (preg_match("/\<(div|DIV)([[:space:]])+(id|ID)\=(\"|')" . $id . "(\"|')(.*?)\<\/(div|DIV)\>/s", $post->post_content, $matches)) { $aside = $matches[0]; } else { $aside = "Aside: div " . $id . " not found"; } break; } break; default : $aside = "Aside: syntax error"; break; } $aside = $prefix . $aside . $suffix; break; default : if ($instance['parse']) { $aside = widget_parse($aside); } break; } } echo $before_widget . $aside . $after_widget; } } } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['parse'] = isset($new_instance['parse']); return $instance; } function form( $instance ) { ?>

/> 

Specify output for this widget by including a custom field named 'aside' in a post/page

ID, 'aside'))) { foreach ($asides as $aside) { if ((strlen($aside) > 2) && ($aside[0] == '!') && ($aside[1] != '!')) { $parts = explode(',', $aside); $id = substr($parts[0], 1); $text = preg_replace("/\<(div|DIV)([[:space:]])+(id|ID)=(\"|')" . $id . "(\"|')/s", "