• Resolved Harish Chouhan

    (@hchouhan)


    Hello,

    I want to display certain images based on specific page and its sub pages. What I need to do is, set a same image for a page and all its sub pages. Am using is_page() with the page ID, but is there any WordPress way to also have a condition based on sub pages of a certain page.

    Am using below code in my header.php

    <?php if (is_page(‘114’) or $post->post_parent) { ?>
    IMAGE 1
    <?php } elseif (is_page(‘115’) or $post->post_parent) { ?>
    IMAGE 2
    <?php } else { ?>
    IMAGE 3
    <?php } ?>

    $post->post_parent is not working. Is there something like $post->post_parent(‘2’)?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to detect if current page is sub page of a certain page?’ is closed to new replies.