How can I modify this code to include the parent?

There are many way to do that and WordPress has some default functions to get that parent page. In fact there is a thing called post_parent in post object. However, you can use the below techniques I think-

  1. get_post_ancestors( $post ) function. Here $post is ID or object. Here you’ll find the documentation.

  2. You can also use wp_get_post_parent_id( $post_ID ). Here you’ll find the documentation.

  3. You can also do that by getting the post_parent like
    $post->post_parent. Then use get_post() or any other function to get that page variable name.

Hope that thing helps.