WordPress Check If Current Category Has Children

function category_has_children() {
global $wpdb;
$term = get_queried_object();
$category_children_check = $wpdb->get_results(" SELECT * FROM wp_term_taxonomy WHERE parent = '$term->term_id' ");
if ($category_children_check) {
return true;
} else {
return false;
}
}

<?php
if (!category_has_children()) {
//use whatever loop or template part here to show the posts at the end of the line
get_template_part('loop', 'index');
} else {
// show your category index page here
}
?>

SQL Count Posts in Category

<?php

function count_posts($cat_id){
global $wpdb;

$query = "
SELECT COUNT(*) FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships ON
($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON
($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
WHERE $wpdb->posts.post_status = 'private'
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->term_taxonomy.term_id = $cat_id
";
return $wpdb->get_var($query);
}

?>

Refine search by category

//Add this to the search.php file, just above the wordpress loop
<?php $search_category = $_GET['category']; ?>
<?php query_posts('&cat=' . $search_category); ?>

//Add this wherever you want to display the search form

<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/" class="search-form">
<input type="text" value="Search" name="s" id="s" class="field" />
<select name="category">
<?php
$categories = get_categories();
foreach ($categories as $cat){ ?>
<option value="<?php echo $cat->cat_ID; ?>" <?php if($cat->cat_ID == 3) echo 'selected="selected"'; ?>><?php echo $cat->cat_name; ?></option>
<?php
}
?>
</select>
<input class="submitsearch button" type="submit" name="submit" value="Search" />
</form>

Create category term

//Initilize Plugin
if(!is_term("WP Videos", "category")){
$arg = array('description' => "Main category for all of the WP Video Player videos", 'parent' => 3);
$new_cat_id = wp_insert_term("WP Videos", "category", $arg);
}

Category Exists

<?php if(check_if_cat_exists('uncategorized')) echo "Category Exists"; ?>

function check_if_cat_exists($category_name){
$category_to_check = get_category_by_slug($category_name);
if (!empty($category_to_check)) return true;
}

Exclude cats from the_category()

//Exlude cats from the_category()
function incomplete_cat_list($separator) {
$first_time = 1;
foreach((get_the_category()) as $category) {
if ($category->cat_name != 'ExcludeCat1' && $category->cat_name != 'ExcludeCat2') {
if ($first_time == 1) {
echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>';
$first_time = 0;
} else {
echo $separator . '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>';
}
}
}
}

//Add the above code to functions.php

//Use this to call the function <?php incomplete_cat_list(', '); ?>

Category ID and Name List

<?php
//Category ID ~ Name List
function hyper_id_name_widget_function() {

$categories=get_categories('orderby=id');
foreach($categories as $category) {
echo '<p>Cat ' . get_cat_ID($category->name) . ' = <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p>';
}
}
function hyper_id_name_widget() {
wp_add_dashboard_widget('hyper_id_name_widget', 'Category ID ~ Name List', 'hyper_id_name_widget_function');
}
add_action('wp_dashboard_setup', 'hyper_id_name_widget' );

?>

Sidebar category highlighting

/* Sidebar link highlighting for the children of a category */
.widget ul.children li.current-cat a:link, .widget ul.children li.current-cat a:visited {
color: #80552B;
}
/* Sidebar link highlighting for the parent category */
.widget li.current-cat a:link, .widget li.current-cat a:visited {
color: #80552B;
}
/* Overwrite the rule that highlights all the children of the parent */
.widget ul.children li a:link, .widget ul.children li a:visited {
color: #2D2F31;
}