How to show only the child page of the page displayed and make it dynamic on wordpress

It may sound silly, but apparently i am not able to show the only the child page of the page displayed on the sidebar.

My structure is

Read More
PAGE 1
-PAGE 1A
-PAGE 1B
-PAGE 1C
PAGE 2
-PAGE 2A
-PAGE 2B
-PAGE 2C

What i want is: when the user is on PAGE 1

-PAGE 1A
-PAGE 1B
-PAGE 1C

I tried all the plugins and all the code available on line (all the code I found ion this website as well about child page), but what i get is:

PAGE 1
-PAGE 1A
-PAGE 1B
-PAGE 1C
PAGE 2
-PAGE 2A
-PAGE 2B
-PAGE 2C

The whole structure. Maybe I am doing something wrong with the theme itself (this is the first time I start with theme from scratch).

I am using this code:

   <?php if ( is_page( 'PAGE 1' )  ) { ?>


    <ul>
      <?php
      wp_list_pages("title_li=&child_of=2&show_date=modified
      &date_format=$date_format"); ?>
    </ul>


    <?php } elseif ( is_page( 'PAGE 2' )   ) { ?>


    <ul>
      <?php
      wp_list_pages("title_li=&child_of=9&show_date=modified
      &date_format=$date_format"); ?>
    </ul>


    <?php } else { ?>

    <ul>
      <?php
      wp_list_pages("title_li=&child_of=7&show_date=modified
      &date_format=$date_format"); ?>
    </ul>



    <?php } ?>

But apparently it doesn’t understand what the page is and goes with the ELSE..

Can you help? What am I doing wrong?

Thanks

Related posts

Leave a Reply

1 comment

  1. I am not sure the the way you write the page title is correct in condition, why not use the page id instead:

    <?php if( is_page(2)  ) { ?>
    
    <ul>
      <?php  wp_list_pages("title_li=&child_of=2&show_date=modified
             &date_format=$date_format"); ?>
    </ul>
    
    <?php } elseif ( is_page(9) ) { ?>
    
    <ul>
      <?php  wp_list_pages("title_li=&child_of=9&show_date=modified
             &date_format=$date_format"); ?>
    </ul>
    
    <?php } else { ?>
    
    <ul>
      <?php   wp_list_pages("title_li=&child_of=7&show_date=modified
              &date_format=$date_format"); ?>
    </ul>
    
    <?php } ?>