WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] is_page(‘ID’)

[Resolved] is_page(‘ID’)

  • I swear, one of these days I will have to give back to the WordPress community.

    With the following code I am using to display child pages on certain parent pages… can I adjust the is_page('21') tag to add additional page IDs?

    <?php if (is_page('21')) : ?>
    <?php wp_list_pages('title_li=&child_of=21'); ?>
    <?php else : ?>
    <?php endif; ?>

    I hope that makes sense.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hmm. The child_of parameter under wp_list_pages() needs to be taken into account, so try:

    <?php if ( is_page(21) || is_page(22)  || is_page(23) ) : ?>
    <?php wp_list_pages('title_li=&child_of=' . $post->ID); ?>
    <?php endif; ?>

    Just add another

    || is_page(#)

    into your if() for each new Page you need to test for (|| is PHP for OR); $post->ID by default should hold the numeric ID of the current post…er, Page.

    Aside: The empty else: is unnecessary, so I dropped it here.

    Thanks for replying Kafkaesqui.

    The code worked perfectly when I adjusted it to the following:

    <?php if ( is_page('2') || is_page('29')  || is_page('30') ) : ?>
    <?php wp_list_pages('title_li=&child_of=2'); ?>
    <?php endif; ?>

    Thank you very much for your help!

    Hmm, seems I misread your request (RE: child_of issue). Glad things work.

    Or I didn’t word it right. 🙂 Im still learning PHP.

    Either way, your code put me on the right track.

    Thanks again.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] is_page(‘ID’)’ is closed to new replies.