Category and Post ID worksheet

<?php
 // This function retreives category ID from an archive page
 function getCurrentCatID(){ 
  global $wp_query; 
  if(is_category() || is_single()){ 
   $cat_ID = get_query_var('cat');
  } 
   return $cat_ID; 
 } 
 echo 'Function Category ID = ';
 echo getCurrentCatID();
 
 echo 'Function Category ID = ' . get_query_var('cat');
 ?>
    
    <br />
 
 
 <?php
 //This retreives category ID from an archive page
 echo 'Cat = ' . get_query_var('cat');
 ?>
  
 <br />
  
  
   <?php
   //The Category ID - In and Out (Use False to prevent echo) *only works for child category
   echo 'Category ID = ';
   the_category_ID( );
   ?>

      <br />
     
      <?php echo 'Category Name = ' . get_cat_name(the_category_ID(false)); ?>
     
      <br />

      <?php
   if (cat_is_ancestor_of( 53 , the_category_ID(false))){
  echo 'In Category 53? = Yes';
   } else echo 'In Category 53? = No';
   ?>
     
      <br />
     
      <?php //$post-> ID - In and Out
   echo 'Post ID = ' . $post->ID;
   ?>
     
      <br />
     
      <p>Begin WordPress Loop</p>
     
     
     
      <!-- ~~~~~~~~~~~~~~ The Loop ~~~~~~~~~~~~~~~ -->
     
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
     
   
     
      <?php //Get The ID - Loop Only
   echo 'Post ID = ' . get_the_ID();
   ?>
  
   <br />
  
   <?php //The ID - Loop Only (Use False to prevent echo)
   echo 'Post ID = ';
   the_ID();
   ?>
  
   <?php endwhile; endif; ?>

Count posts in a category

<?php
function wt_get_category_count($input = '') {
global $wpdb;
if($input == '')
{
$category = get_the_category();
return $category[0]->category_count;
}
elseif(is_numeric($input))
{
$SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.term_id=$input";
return $wpdb->get_var($SQL);
}
else
{
$SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->terms.slug='$input'";
return $wpdb->get_var($SQL);
}
}
?>

<!-- Get current category -->
<?php echo wt_get_category_count(); ?>
<!-- Get category 1 -->
<?php echo wt_get_category_count(1); ?>
<!-- Get category 'hello-world' -->
<?php echo wt_get_category_count('hello-world'); ?>

Get current category ID

<?php

function getCurrentCatID(){

global $wp_query;

if(is_category() || is_single()){

$cat_ID = get_query_var('cat');
}

return $cat_ID;

}

echo getCurrentCatID();

?>