Widget Logic
[resolved] Only for parent and child pages? (5 posts)

  1. kriskrukkert
    Posted 3 years ago #

    I want a widget containing a submenu only to show up when a page is a parent or child page.

    Is this posible and how?

    thanks in advance


  2. isle2isle
    Posted 2 years ago #

    I'm looking for an answer to this too.

  3. alanft
    Plugin Author

    Posted 2 years ago #

    i googled this


    which suggests you could do this for when a page has children

    global $post; return (count(get_pages('child_of='.$post->id))>0);

    this for checking the page has a parent

    global $post; return($post->post_parent != 0);

    and then combine when either is true with

    global $post; return (count(get_pages('child_of='.$post->id))>0) || ($post->post_parent != 0);

    i'd be interested to know if that works

  4. isle2isle
    Posted 2 years ago #

    That didn't work, but I finally got this to do it.
    (Replace '123' in the line below with the parent page ID number)

    global $post; return (is_page('123') || ($post->post_parent=="123"));

  5. alanft
    Plugin Author

    Posted 2 years ago #

    great, glad you're sorted.

    that's the solution for a specific page or the children of a specific page.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic