• Hello there,

    I have little catalog based on WP pages. I wanted to apply contact form for product pages, but faced with a problem – I need to load different contact form depend on parent page. So I come up with this code:

    <?php if ( is_page(215) && $post->post_parent ):
        echo 'contact form';
    else ( is_page(230) && $post->post_parent ):
        echo 'contact form 2';
    endif; ?>

    Anything I’ve tried doesn’t work, can you tell me why?

    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello,
    please try this code.
    global $post;

    <?php if ( $post->ID == ‘215’ && $post->post_parent ){
    echo ‘contact form’;
    }
    elseif( $post->ID == ‘230’ && $post->post_parent ){
    echo ‘contact form 2’;
    } ?>

    Thread Starter theredeclipse

    (@theredeclipse)

    Thanks, but for some reason I got a blank page with this code.

    i think single quotes causing issue plz try this code.
    if ( $post->ID == ‘215’ && $post->post_parent ){
    echo ‘contact form’;
    }
    elseif( $post->ID == ‘230’ && $post->post_parent ){
    echo ‘contact form 2’;
    }

    Thread Starter theredeclipse

    (@theredeclipse)

    Sadly but still blank page.

    can you plz remove above code and check, is page still blank ?
    and also check this link https://www.screencast.com/t/J2sDaiFrJ
    how to fix single quote issue.

    Thread Starter theredeclipse

    (@theredeclipse)

    Oh, I tried before to replace single quote, but maybe misspelled or something, page is loads now, thanks. But code nothing returns, there’s none “contact form” nor “contact form 2”

    can you send me link of page may be you are using wrong id or you can check this code
    where “$post->post_parent == 0” indicate that is parent page
    again change the single quote.

    if ( $post->ID == ‘215’ && $post->post_parent == 0 ){
    echo ‘contact form’;
    }
    elseif( $post->ID == ‘230’ && $post->post_parent == 0 ){
    echo ‘contact form 2’;
    }

    Thread Starter theredeclipse

    (@theredeclipse)

    Thanks a bunch! Everything works as should. <3

    Moderator bcworkz

    (@bcworkz)

    @leadsoft – thanks for helping out in the forums! The best way to fix the “curly quote” issue in these forums is to demarcate your code with `backticks` or use the “code” button. Much better than trying to explain to others how to manually edit your code that got corrupted by the forum parser ??

    Your initial code when backticks are used:

    if ( $post->ID == '215' && $post->post_parent ){
    echo 'contact form';
    }
    elseif( $post->ID == '230' && $post->post_parent ){
    echo 'contact form 2';
    }
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Conditional logic depend on parent page’ is closed to new replies.