0 View'; } return '' . number_format($count) . ' ' . __('Views', 'blognowlite'); } endif; /** * Set Post Views. */ if ( ! function_exists( 'blognowlite_set_post_views' ) ) : function blognowlite_set_post_views($postID) { $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); }else{ $count++; update_post_meta($postID, $count_key, $count); } } endif; /** * Search Filter */ if ( ! function_exists( 'blognowlite_search_filter' ) ) : function blognowlite_search_filter($query) { if ($query->is_search) { $query->set('post_type', 'post'); } return $query; } add_filter('pre_get_posts','blognowlite_search_filter'); endif; /** * Filter the except length to 20 characters. * * @param int $length Excerpt length. * @return int (Maybe) modified excerpt length. */ if ( ! function_exists( 'blognowlite_custom_excerpt_length' ) ) : function blognowlite_custom_excerpt_length( $length ) { return get_theme_mod('entry-excerpt-length', '20'); } add_filter( 'excerpt_length', 'blognowlite_custom_excerpt_length', 999 ); endif; /** * Customize excerpt more. */ if ( ! function_exists( 'blognowlite_excerpt_more' ) ) : function blognowlite_excerpt_more( $more ) { return '... '; } add_filter( 'excerpt_more', 'blognowlite_excerpt_more' ); endif; /** * Add custom meta box. */ if ( ! function_exists( 'blognowlite_add_custom_meta_box' ) ) : function blognowlite_add_custom_meta_box() { add_meta_box("demo-meta-box", "Post Options", "blognowlite_custom_meta_box_markup", "post", "side", "high", null); } add_action("add_meta_boxes", "blognowlite_add_custom_meta_box"); endif; /** * Displaying fields in a custom meta box. */ if ( ! function_exists( 'blognowlite_custom_meta_box_markup' ) ) : function blognowlite_custom_meta_box_markup($object) { wp_nonce_field(basename(__FILE__), "meta-box-nonce"); ?>
ID, "is_featured", true); if($checkbox_value == "") { ?>
post_type) return $post_id; $meta_box_text_value = ""; $meta_box_textarea_value = ""; $meta_box_checkbox_value = ""; if(isset($_POST["is_featured"])) { $meta_box_checkbox_value = $_POST["is_featured"]; } update_post_meta($post_id, "is_featured", $meta_box_checkbox_value); } add_action("save_post", "blognowlite_save_custom_meta_box", 10, 3); endif; /** * Display the first (single) category of post. */ if ( ! function_exists( 'blognowlite_first_category' ) ) : function blognowlite_first_category() { $category = get_the_category(); if ($category) { echo 'name ) . '" ' . '>' . $category[0]->name.' '; } } endif; /** * Returns true if a blog has more than 1 category. * * @return bool */ if ( ! function_exists( 'blognowlite_categorized_blog' ) ) : function blognowlite_categorized_blog() { if ( false === ( $all_the_cool_cats = get_transient( 'blognowlite_categories' ) ) ) { // Create an array of all the categories that are attached to posts. $all_the_cool_cats = get_categories( array( 'fields' => 'ids', 'hide_empty' => 1, // We only need to know if there is more than one category. 'number' => 2, ) ); // Count the number of categories that are attached to the posts. $all_the_cool_cats = count( $all_the_cool_cats ); set_transient( 'blognowlite_categories', $all_the_cool_cats ); } if ( $all_the_cool_cats > 1 ) { // This blog has more than 1 category so blognowlite_categorized_blog should return true. return true; } else { // This blog has only 1 category so blognowlite_categorized_blog should return false. return false; } } endif; /** * Flush out the transients used in blognowlite_categorized_blog. */ if ( ! function_exists( 'blognowlite_category_transient_flusher' ) ) : function blognowlite_category_transient_flusher() { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } // Like, beat it. Dig? delete_transient( 'blognowlite_categories' ); } add_action( 'edit_category', 'blognowlite_category_transient_flusher' ); add_action( 'save_post', 'blognowlite_category_transient_flusher' ); endif; /** * Add link to Admin Bar. */ if ( ! function_exists( 'blognowlite_custom_toolbar_link' ) ) : function blognowlite_custom_toolbar_link($wp_admin_bar) { $args = array( 'id' => 'happythemes', 'title' => '→ WordPress Themes', 'href' => 'https://www.happythemes.com/wordpress-themes', 'meta' => array( 'class' => 'happythemes', 'title' => 'Click to get more WordPress themes', 'target'=> '_blank', ) ); $wp_admin_bar->add_node($args); } add_action('admin_bar_menu', 'blognowlite_custom_toolbar_link', 999); endif;