How to write short code with if else to get page_id?

I use this maybe helpfull

<?php
   $title = get_the_title($post); 
   $parent_title = get_the_title($post->post_parent);

   echo $title;
   echo $parent_title;
  ?>


<?php
  global $post; //wordpress post global object
  if($post->post_type == 'page'){
    $content .= '<br /> This item is a page and the ID is: '.$post->ID;
  } elseif($post->post_type == 'post') {
    $content .= '<br /> This item is a post and the ID is: '.$post->ID;
  }
  echo $content;

?>