WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. kriskrukkert
    Member
    Posted 1 year 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

    http://wordpress.org/extend/plugins/widget-logic/

  2. isle2isle
    Member
    Posted 1 year ago #

    I'm looking for an answer to this too.

  3. alanft
    Member
    Plugin Author

    Posted 1 year ago #

    i googled this

    http://www.wpgeek.com/tutorials/how-to-check-if-wordpress-page-have-subpages-or-childrens/

    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
    Member
    Posted 1 year 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
    Member
    Plugin Author

    Posted 1 year 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