WordPress.org

Ready to get started?Download WordPress

Forums

pages plus subpages conditional tag (3 posts)

  1. alby54
    Member
    Posted 1 year ago #

    Hi, I created various template_parts which are recalled by page name.
    The code is like this:

    <?php get_template_part( $slug, $name );
    if ( is_page( 'page_one' ) ) :
    	get_template_part( 'media-page_one' );
    elseif ( is_page( 'page_two' ) ) :
    	get_template_part( 'media-page_two' );
    else :
      get_template_part('');
    endif
    ?>

    How can I change this code so even the child pages get included?
    I tried:

    if ( is_page( 'page_one' ) || 'page_one' == $parent_name ) :
    	get_template_part( 'media-page_one' );

    ...bur it doesn't work. What am I missing?

    thanks for any hint

    Alby

  2. Slobodan Manic
    Member
    Posted 1 year ago #

    Alby,

    I think Snippet 4 here should get you in the right track:

    http://codex.wordpress.org/Conditional_Tags#Testing_for_sub-Pages

  3. alby54
    Member
    Posted 1 year ago #

    Thank you Slobodan meanwhile I found exactly the same snippet and that's the one I'm using together with the relative function. The only thing that is kind of annoying is that the script does not work with names .....only IDs which is kind of a pain having about 40 pages to include in the if ...else....
    thank you anyway

Topic Closed

This topic has been closed to new replies.

About this Topic