WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Widget Logic - How to exclude children and grandchilren (2 posts)

  1. leet8845
    Member
    Posted 4 years ago #

    Hi all,

    I'm trying to use Widget Logic to exclude widgets from children and grandchildren of a particular page on my site. The code I'm using only work for the page and it's children but not the grandchildren and I don't know how to include them.

    Here is my code;
    global $post; return !(is_page(219) || ($post->post_parent=="219"));

    How can I add another 2 pages to this? I've tried my interpretation of 'logic' but it hasn't prevailed. Any help is truly appreicated

  2. leet8845
    Member
    Posted 4 years ago #

    I got this solved by Alan over at freakytrigger.co.uk

    He said
    "“I want to exclude all the children of 219, 409 and 357″

    then you need to add || ($post->post_parent==”219″) in there too – which is doing the job of excluding the children of 219. the is_page(219) will also exclude page 219.

    when the code is getting a bit repetitious like this, you could try reformulating using PHP’s in_array like this:

    global $post; return !( in_array($post->post_parent, array(219,357,409)) );

    wordpress’s own is_page can take an array for multiple values too, so if you also wanted to exclude those parent pages:

    global $post; return !( is_page(array(219,357,409)) || in_array($post->post_parent, array(219,357,409)) );"

    I used 'global $post; return !( is_page(array(219,357,409)) || in_array($post->post_parent, array(219,357,409)) )'

    It works perfect! Thanks again Alan! Your the man!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.