I would like users of my theme to be able to mark some posts as more important so that my theme can draw more attention to them. I'm not sure about the best way to go about this? Is it possible to add a default category of 'featured' to a theme that will be there as an option when anybody installs my theme?
edit: Taking the approach of adding a custom meta-box in the admin screen: Should something like this work?
function featured_post() { ?>
<label><input type="checkbox" id="meta-box-checkbox"id="featured_post" value="featured_post">Make this a featured post</label>;
<?php }
add_action('add_meta_boxes', 'cd_meta_box_add');
function cd_meta_box_add() {
add_meta_box(1, 'Featured Post', 'featured_post');
}
function save_custom_meta_box($post_id, $post, $update)
{
if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-box-nonce"], basename(__FILE__)))
return $post_id;
if(!current_user_can("edit_post", $post_id))
return $post_id;
if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)
return $post_id;
$slug = "post";
if($slug != $post->post_type)
return $post_id;
$meta_box_checkbox_value$featured_post_value = "";
if(isset($_POST["meta-box-checkbox"]$_POST["featured_post"]))
{
$meta_box_checkbox_value$featured_post_value = $_POST["meta-box-checkbox"];$_POST["featured_post"];
}
update_post_meta($post_id, "meta-box-checkbox""featured_post", $meta_box_checkbox_value$featured_post_value);
}
add_action("save_post", "save_custom_meta_box", 10, 3);
function annframe_featured_class( $classes ) {
global $post;
if ( get_post_meta( $post->ID, 'featured_post' ) || '' != get_post_meta( $post->ID, 'featured_post' ) ) {
$classes[] = 'featured-post';
}
return $classes;
}
add_filter( 'post_class', 'annframe_featured_class' );