Check parent ID

if ($post->post_parent) {
$ancestors=get_post_ancestors($post->ID);
$root=count($ancestors)-1;
$parent = $ancestors[$root];
} else {
$parent = $post->ID;
}

Get Page ID

$this_page_id = get_query_var('page_id');

$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");

$post->ID

Parent Cat ID for single.php

<?php

foreach((get_the_category()) as $childcat) {

$parentcat = $childcat->category_parent;

$the_cat_name = get_cat_name($parentcat);

$the_cat_ID = get_cat_ID($the_cat_name);

}
if($the_cat_ID == 4){
echo "parent cat $the_cat_ID <br />";
}
?>

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; ?>

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();

?>