array( 'name' => __( 'Microposts' ), 'singular_name' => __( 'Micropost' ), ), 'has_archive' => true, 'menu_icon' => plugins_url( 'microblogging-icon.png', __FILE__ ), 'menu_position' => 5, 'public' => true, 'rewrite' => array( 'slug' => 'microposts' ), 'supports' => array( 'title', 'editor', 'author', 'comments' ), // uncomment to support categories and tags: // 'taxonomies' => array ( 'category', 'post_tag' ), ) ); } /* * Tells wordpress to reset its permalink structure, to accommodate the new post type */ register_activation_hook( __FILE__, 'my_rewrite_flush' ); function my_rewrite_flush() { create_micropost_type(); flush_rewrite_rules(); } /* * Microblog widget code */ add_action('widgets_init', 'ahspfc_load_widgets'); function ahspfc_load_widgets() { register_widget('microblog_widget'); } class microblog_widget extends WP_Widget { function microblog_widget() { $widget_ops = array( 'classname' => 'microblog_widget', 'description' => 'Allows you to display a list of microblog entries while excluding them from posts.', ); $control_ops = array( 'id_base' => 'microblog-widget', ); $this->WP_Widget('microblog-widget', 'Microblog', $widget_ops, $control_ops ); } function form ($instance) { $defaults = array( 'numberposts' => '5', 'title' => '', 'rss' => '', ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>

/>

/>

"; while ( $query_results->have_posts() ) { $query_results->the_post(); $out .= "
  • "; $post_title = the_title( '', '', false ); if ( $post_title ) { $out .= "" . $post_title . " "; } $out .= ""; if ( $use_excerpt ) { add_filter('excerpt_more', 'micropost_excerpt_more'); $out .= get_the_excerpt(); remove_filter('excerpt_more', 'micropost_excerpt_more'); } else { $out .= $post->post_content; } $out .= ""; $out .= ""; $out .= " "; $out .= ""; $out .= "×" . get_comments_number(); $out .= ''; $out .= "\n"; $out .= "
  • \n"; } $out .= ""; //print the widget for the sidebar echo $before_widget; echo $before_title; echo $title; if ($rss) { echo ' '; echo ''; echo ''; } echo $after_title; echo $out; echo $after_widget; // clean up wp_reset_postdata(); } } /* * Microblog shortcode code */ add_shortcode( 'microblog', 'microblog_shortcode' ); function microblog_shortcode($atts) { global $post; // Arguments to the shortcode extract( shortcode_atts( array( 'num' => '5', 'null_text' => '(none)', 'show_date' => '', 'date_format' => get_option('date_format'), // I recommend 'F j' 'use_excerpt' => '', 'q' => '', ), $atts ) ); if ( $q ) { $q = str_replace ( "&", "&", $q ); } /* * query the database for tweets! * query syntax: * http://codex.wordpress.org/Class_Reference/WP_Query#Parameters */ $query .= "post_type=micropost&posts_per_page=" . $num; if ( $q ) { $query .= "&" . $q; } $query_results = new WP_Query($query); if ( $query_results->post_count == 0 ) { return "

    " . wp_kses($null_text,array()) . "

    \n"; } $out = ""; // clean up wp_reset_postdata(); return $out; } function micropost_excerpt_more($more) { return ' ...'; } /* * Load our default style sheet */ add_action( 'wp_print_styles', 'microblog_enqueue_styles' ); function microblog_enqueue_styles() { wp_register_style( 'simple-microblogging', plugins_url('simple-microblogging.css', __FILE__) ); wp_enqueue_style( 'simple-microblogging' ); } ?>