'; // were there any posts found? if (!empty($posts)) { // posts were found, loop through them foreach ($posts as $post) { // format a date for the posts $post->post_date = date("F j, Y",strtotime($post->post_date)); // if we want to display an excerpt, get it/generate it if no excerpt found if ($excerpt) { if (empty($post->post_excerpt)) { $post->post_excerpt = explode(" ",strrev(substr(strip_tags($post->post_content), 0, 100)),2); $post->post_excerpt = strrev($post->post_excerpt[1]); $post->post_excerpt.= " [...]"; } } //output to screen echo '
  • '.$post->post_title.''; echo '
  • '; } } else echo "
  • No recent Posts
  • "; // end list echo ''; // echo widget closing tag echo $after_widget; } // Settings form function widget_myRecentPosts_control() { // Get options $options = get_option('widget_myRecentPosts'); // options exist? if not set defaults if ( !is_array($options) ) $options = array('title'=>'Recent Posts', 'show'=>'5', 'excerpt'=>'1','exclude'=>''); // form posted? if ( $_POST['myRecentPosts-submit'] ) { // Remember to sanitize and format use input appropriately. $options['title'] = strip_tags(stripslashes($_POST['myRecentPosts-title'])); $options['show'] = strip_tags(stripslashes($_POST['myRecentPosts-show'])); $options['excerpt'] = strip_tags(stripslashes($_POST['myRecentPosts-excerpt'])); $options['exclude'] = strip_tags(stripslashes($_POST['myRecentPosts-exclude'])); update_option('widget_myRecentPosts', $options); } // Get options for form fields to show $title = htmlspecialchars($options['title'], ENT_QUOTES); $show = htmlspecialchars($options['show'], ENT_QUOTES); $excerpt = htmlspecialchars($options['excerpt'], ENT_QUOTES); $exclude = htmlspecialchars($options['exclude'], ENT_QUOTES); // The form fields echo '

    '; echo '

    '; echo '

    '; echo '

    Enter the categories to exclude below, this must be a comma seperated list of category id\'s!

    '; echo '

    '; echo ''; } // Register widget for use register_sidebar_widget(array('My Recent Posts', 'widgets'), 'widget_myRecentPosts'); // Register settings for use, 300x100 pixel form register_widget_control(array('My Recent Posts', 'widgets'), 'widget_myRecentPosts_control', 300, 200); } // Run code and init add_action('widgets_init', 'widget_myRecentPosts_init'); ?>