Add Featured Image Thumbnail to Posts Page

Customize the information that is displayed on the ‘posts’ page

Adding a column labeled “Thumbnail” (and delete the “Comments” column).

add_filter( 'manage_edit-post_columns', 'set_columns' );
function set_columns($columns) {
	$columns['thumbnail'] = 'Thumbnail';
	unset( $columns['comments'] );
	return $columns;
}

Now we need to tell WordPress what to do with this new “Thumbnail” space. Here, we’re checking for the existence of a featured image and displaying it, or noting that there is no thumbnail.

add_action( 'manage_posts_custom_column', 'fill_columns' );
function fill_columns($column) {
	global $post;
	switch($column) {
		case 'thumbnail' :
			if (has_post_thumbnail($post->ID))
				echo get_the_post_thumbnail($post->ID, array(50, 50));
			else
				echo '<em>no thumbnail</em>';
		break;
	}
}

Hide Menu Items

If you need to hide menus from the sidebar of the administration area, you can use this. Keep in mind, this method does not block access, just hides the link.

add_action('admin_menu', 'hide_menu_links');
function hide_menu_links(){
  	global $menu,$submenu;

  	if ($submenu['plugins.php'][15][0] == 'Editor')
	unset($submenu['plugins.php'][15]);

  	if ($menu[15][0] == 'Links')
	unset($menu[15]);

}
// $menu
//     [2] => {Dashboard}
//     [4] => {separator}
//     [5] => {Posts}
//     [10] => {Media}
//     [15] => {Links}
//     [20] => {Pages}
//     [25] => {Comments}
//     [59] => {separator}
//     [60] => {Appearance
//     [65] => {Plugins}
//     [70] => {Users}
//     [75] => {Tools}
//     [80] => {Settings}
//     [99] => {separator}

// $submenu
//     [index.php] =>
//         [0] => {Dashboard}
//         [10] => {Updates}
//     
//     [edit.php] =>
//         [5] => {Posts}
//         [10] => {Add New}
//         [15] => {Categories}
//         [16] => {Post Tags}
//     
//     [upload.php] =>
//         [5] => {Library}
//         [10] => {Add New}
//     
//     [link-manager.php] =>
//         [5] => {Links}
//         [10] => {Add New}
//         [15] => {Link Categories}
//     
//     [edit.php?post_type=page] =>
//         [5] => {Pages}
//         [10] => {Add New}
//     
//     [themes.php] =>
//         [5] => {Themes}
//         [7] => {Widgets}
//         [10] => {Menus}
//     
//     [plugins.php] =>
//         [5] => {Plugins}
//         [10] => {Add New}
//         [15] => {Editor}
//     
//     [users.php] =>
//         [5] => {Users}
//         [10] => {Add New}
//         [15] => {Your Profile
//     
//     [tools.php] =>
//         [5] => {Tools}
//         [10] => {Import}
//         [15] => {Export}
//     
//     [options-general.php] =>
//         [10] => {General}
//         [15] => {Writing}
//         [20] => {Reading}
//         [25] => {Discussions}
//         [30] => {Media}
//         [35] => {Privacy}
//         [40] => {Permalinks}

Simple “Upcoming Posts” Widget

Here’s a simple widget for displaying upcoming posts. Title of widget and number of posts shown is configurable.

add_action( 'widgets_init', 'upcoming_posts_widget_load_widget' ); /* Add our function to the widgets_init hook. */
function upcoming_posts_widget_load_widget() { register_widget( 'upcoming_posts_widget' ); } /* Function that registers our widget. */

class upcoming_posts_widget extends WP_Widget {

    function upcoming_posts_widget() {
        $widget_ops = array( 'classname' => 'upcoming_posts', 'description' => 'Upcoming Posts Widget' ); /* Widget settings. */
        $control_ops = array(  'id_base' => 'upcoming_posts' ); /* Widget control settings. */
        $this->WP_Widget( 'upcoming_posts', 'Upcoming Posts Widget', $widget_ops, $control_ops ); /* Create the widget. */
    }

    function widget( $args, $instance ) {
        extract( $args );  /* before/after widget, before/after title (defined by themes). */
        extract($instance);

        echo $before_widget;
        echo $before_title . $title . $after_title; 

        echo '<ul>';
        $posts = get_posts("post_status=future&numberposts=$numberposts&order=ASC");
        $posts = array_reverse($posts);
        foreach ($posts as $p) {
            echo '<li>'. $p->post_title .'</li>';
        }
        echo '</ul>';
        echo $after_widget; 
    }

    function update( $new_instance, $old_instance ) {
        $instance = $old_instance;
        $instance['title'] = strip_tags( $new_instance['title'] );
        $instance['numberposts'] = (int) $new_instance['numberposts'];
        return $instance;
    }

    function form( $instance ) {
        $defaults = array( 'title' => 'Upcoming Posts', 'numberposts' => 3 );
        $instance = wp_parse_args( (array) $instance, $defaults );
    ?>
        <p>
            <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
            </select>
        </p>
        <p>
            <label for="<?php echo $this->get_field_id( 'numberposts' ); ?>">Number Posts:</label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'numberposts' ); ?>" name="<?php echo $this->get_field_name( 'numberposts' ); ?>" value="<?php echo $instance['numberposts']; ?>" />
            </select>
        </p>
    <?php
    }
}

Custom Post Types

Adding a new post type, for when ‘posts’ and ‘pages’ just won’t do.

add_action( 'init', 'my_new_post_types' );
function my_new_post_types() {
    $labels = array(
        'name' => _x('Hotels', 'post type general name'),
        'singular_name' => _x('Hotel', 'post type singular name'),
        'add_new' => _x('Add New', 'hotel'),
        'add_new_item' => __('Add New Hotel'),
        'edit_item' => __('Edit Hotel'),
        'new_item' => __('New Hotel'),
        'view_item' => __('View Hotel'),
        'search_items' => __('Search Hotels'),
        'not_found' =>  __('No hotels found'),
        'not_found_in_trash' => __('No hotels found in Trash'), 
        'parent_item_colon' => '',
        'menu_name' => 'Hotels'    
    );
    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true, 
        'show_in_menu' => true, 
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'has_archive' => true, 
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','author','thumbnail','excerpt','comments')
    ); 
    register_post_type('hotel',$args);
}

Hide Plugin Update count

In case you need to hide the plugin update count (can’t/don’t want to update yet) you can hide it with this. Can be especially useful if you don’t want clients to wander over the the update area.

add_action('admin_menu', 'remove_plugin_update_count');
function remove_plugin_update_count(){
    global $menu, $submenu;
    $menu[65][0] = 'Plugins';
    $submenu['index.php'][10][0] = 'Updates';
}

Custom Taxonomies

When you need more than just ‘categories’ and ‘tags’ use custom taxonomies.

Especially useful in combination with custom post types.

add_action('init', 'my_new_taxonomies');
function my_new_taxonomies() {

	$labels = array(
	'name' => __( 'Action Hooks' ),
	'singular_name' => __( 'Action Hook' ),
	'search_items' =>  __( 'Search Action Hooks' ),
	'popular_items' => __( 'Popular Action Hooks' ),
	'all_items' => __( 'All Action Hooks' ),
	'parent_item' => null,
	'parent_item_colon' => null,
	'edit_item' => __( 'Edit Action Hook' ),
	'update_item' => __( 'Update Action Hook' ),
	'add_new_item' => __( 'Add New Action Hook' ),
	'new_item_name' => __( 'New Action Hook' ),
	'separate_items_with_commas' => __( 'Separate hooks with commas' ),
	'add_or_remove_items' => __( 'Add or remove hooks' ),
	'choose_from_most_used' => __( 'Choose from the most used hooks' ),
	'menu_name' => __( 'Action Hooks' ),
	); 

	register_taxonomy('action_hook','post',array(
	'hierarchical' => false,
	'labels' => $labels,
	'show_ui' => true,
	'query_var' => true,
	'rewrite' => array( 'slug' => 'action_hook' ),
	));
}