HowTo translate this IF Clause?! (4 posts)

  1. Nilsemann
    Posted 9 years ago #

    Hello WPers,

    I have an problem to solve my IF clause. I need to input something in my template that would in simple language be:

    IF current page IS child page OF IDX {....

    Anybody get a clue how to solve this?


  2. This check should do it - Each page has the parent page id stored as an attribute:

    if ($post->post_parent == $id_of_parent_page)

  3. Nilsemann
    Posted 9 years ago #

    Hm thanks for the Tip but I need to declare this in the header. I got some special CSS and a Gallery and only when a subpage of the Galery(ID13)is loaded WP should output the correct CSS...

    example (this is how it is solved now):

    if (is_page('Galerie') or is_page('Landscape') or...{
    echo 'body { ... }';
    } else {
    echo 'body { ... }';
    /?> </style>

    But this means for ever subpage I must edit my headerfile and include another "or is_page..." - this should be solved somehow else in clear language it would be:

    IF current page IS child page OF galerie { .... }

    I think the Vars you gave me are from the loop aren't they? I tried to echo them but theres no output?!

  4. Ok, if you want to run this if check outside the loop you want something like this:

    if (is_page() && $posts[0]->post_parent == $id_of_parent_page)
    //do style stuff here.

    This checks that we are on a page and then uses the global array of posts to look at the page (post 0 in this single post query) and check the value set for post_parent.

    Hope this helps.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.