_x('Article', 'post type general name'), 'singular_name' => _x('article', 'post type singular name'), 'add_new' => _x('Add New', 'article'), 'add_new_item' => __('Add New article'), 'edit_item' => __('Edit article'), 'new_item' => __('New article'), 'view_item' => __('View article'), 'search_items' => __('Search article'), 'not_found' => __('No article found'), 'not_found_in_trash' => __('No article found in Trash'), 'parent_item_colon' => '' ); $supports = array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'custom-fields', 'trackbacks' ); $capabilities = array( 'edit_article' ); $args = array( 'labels' => $labels, 'public' => true, // 'capability_type' => 'post', // 'capabilities' => $capabilities, 'supports' => $supports, 'rewrite' => array('slug' => 'articles') ); register_post_type('article', $args); register_taxonomy_for_object_type( 'category', 'article' ); register_taxonomy_for_object_type( 'post_tag', 'article' ); } /** Add filter so CPT works with category and tag */ if ( ! function_exists( 'query_post_type' ) ) : add_filter('pre_get_posts', 'query_post_type'); function query_post_type($query) { /** * hopefully this won't blow things up on the archive pages * if it does use get_post_types() */ $post_types = get_post_types(); if ( is_category() || is_tag()) { $post_type = get_query_var('article'); if ( $post_type ) $post_type = $post_type; else $post_type = $post_types; $query->set('post_type', $post_type); return $query; } } endif; /** * Add Widget support: * Title * Count * Choose category to display * Choose tag to display * Choose Image to display * Show post on * Show post in * * Requirments: your theme must support Widgets! * The bulk of this class was taken from the codex, see codex for docs * Codex: http://codex.wordpress.org/Widgets_API#Widgets_API * * no need to init, get init'd via wp, see add_action below */ class MostRecentArticles extends WP_Widget { /** constructor */ function MostRecentArticles() { parent::WP_Widget(false, $name = 'Most Recent Articles'); } /** @see WP_Widget::widget */ function widget($args, $instance) { extract( $args ); $title = array('title' => apply_filters('widget_title', $instance['title']), 'count' => apply_filters('widget_count', $instance['count']), 'category' => apply_filters('widget_category', $instance['category']), 'image' => apply_filters('widget_image', $instance['image']), 'posted_on' => apply_filters('widget_image', $instance['posted_on']), 'posted_in' => apply_filters('widget_image', $instance['posted_in']), 'excerpt' => apply_filters('widget_image', $instance['excerpt']) ); echo $before_widget; article_type_mrt($title); echo $after_widget; } /** @see WP_Widget::update */ function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['count'] = strip_tags($new_instance['count']); $instance['category'] = strip_tags($new_instance['category']); $instance['image'] = strip_tags($new_instance['image']); $instance['posted_on'] = strip_tags($new_instance['posted_on']); $instance['posted_in'] = strip_tags($new_instance['posted_in']); $instance['excerpt'] = strip_tags($new_instance['excerpt']); return $instance; } /** @see WP_Widget::form */ function form($instance) { $title = (isset($instance['title'])) ? esc_attr($instance['title']) : 'no title'; $count = (isset($instance['count'])) ? esc_attr($instance['count']) : 0; $category = (isset($instance['category'])) ? esc_attr($instance['category']) : ''; $image = (isset($instance['image'])) ? esc_attr($instance['image']) : 0; $posted_on = (isset($instance['posted_on'])) ? esc_attr($instance['posted_on']) : 0; $posted_in = (isset($instance['posted_in'])) ? esc_attr($instance['posted_in']) : 0; $excerpt = (isset($instance['excerpt'])) ? esc_attr($instance['excerpt']) : 0; /** * Pretty cool, get our regsitered image sizes * Codex: http://core.trac.wordpress.org/browser/tags/3.0.4/wp-includes/media.php */ global $_wp_additional_image_sizes; $image_sizes = $_wp_additional_image_sizes; $categories = get_terms('category'); ?>

{$content}"; return $booo; } add_shortcode('META_BOX', 'article_type_meta_box'); function article_type_meta_box($atts, $content=NULL) { $booo = "
{$content}
"; return $booo; } add_shortcode('ARTICLE_MRT', 'article_type_mrt_box'); function article_type_mrt_box($atts, $content=NULL) { /** If we have attributes from the short code use them */ if ( !empty( $atts )) { /** * Allowed attributes, we're not getting crazy on this ish * @todo check for atts can be more extensive * @todo could possibly add more atts * shortcode_atts returns an array! */ extract( shortcode_atts( array( 'title', 'count', 'category' ), $atts ) ); /** check if things are there */ if ( empty( $atts['title'] ) ) $atts['title'] = 'Recent Articles'; if ( empty( $atts['count'] ) ) $atts['count'] = 5; /** pretty cool, man so much is already done for us :) */ if ( term_exists($atts['category']) ) $atts['category'] = $atts['category']; $args = array( 'count' => $atts['count'], 'category' => $atts['category'], 'title' => $atts['title'] ); } else { $args = array( 'count' => 5, 'image' => 'none', 'category' => 'all', 'title' => 'Recent Articles' ); } return '
' . article_type_mrt($args, false) . '
'; } /** * function: tip_type_mrt() * Params: $title, $count, $image, $topic_term, $skill_term * Requirments: your theme must support Widgets! * * @param $args An array of our arguments * @param $display Bool, default true, used to either return output * as used in the short_code or to print outout */ function article_type_mrt($args=NULL, $display=TRUE) { global $post; /** * Set our default's and checkout our args/params * they come in via an array, yes we trust them */ if (is_array( $args )) extract( $args ); if (is_null( $category )) $category = ''; if (empty( $image ) || $image == 'none') $image = 'no-image'; if ($count == 0 ) $count = 3; if (strtolower( $category ) == 'all') $category = null; /** Build our query for get_posts */ $args = array( 'post_type' => 'article', 'category_name' => $category, 'numberposts'=> $count, 'offset' => 1 ); $myposts = get_posts( $args ); $x = 1; $count = count( $myposts ); if ( empty( $posted_on ) ) $posted_on = null; if ( empty( $posted_in ) ) $posted_in = null; if ( empty( $excerpt ) ) $excerpt = null; $html = null; $html .= "

{$title}

"; /** * @todo take this one step further and pass in the height width of our image * then in the css do something like: overflow: hidden; height: value; width: value; * thus forcing the layout to be correct, or just run "regenerate thumbs!" tanks viper007! */ $html .= ""; /** * sometimes we wanna return * sometimes we wanna print * sometimes we wanna just go... */ if ( !$display ) return $html; else print $html; }