Forums

[resolved] How write a conditional for multiple post parents? (3 posts)

  1. Matt
    Member
    Posted 2 years ago #

    Hello guys,

    Looking to write a condition to show a particualr portion of a navigation if the post parents are 205, 203, 202.

    Here is what I got:

    <?php if(is_page('issues') || $post->post_parent == '205' ){ ?>

    I would like to just add a few more post parent id's is that possible?

    Like:
    <?php if(is_page('issues') || $post->post_parent == '205', '203','202' ){ ?>

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    Example of in_array:

    <?php
    if ( in_array('205', array('205','203','202')) ) {
        echo "205 is in the array";
    }
    ?>
  3. Matt
    Member
    Posted 2 years ago #

    I did it like this and it worked:

    <?php if(is_page('issues') || $post->post_parent == '205' || $post->post_parent == '209' || $post->post_parent == '211' || $post->post_parent == '213'){ ?>

    Thanks MichaelH I will try that as well to get clean code

Topic Closed

This topic has been closed to new replies.

About this Topic