WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] is_page('ID') (5 posts)

  1. 5115
    Member
    Posted 6 years ago #

    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.

  2. Kafkaesqui

    Posted 6 years ago #

    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.

  3. 5115
    Member
    Posted 6 years ago #

    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!

  4. Kafkaesqui

    Posted 6 years ago #

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

  5. 5115
    Member
    Posted 6 years ago #

    Or I didn't word it right. :) Im still learning PHP.

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

    Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic