• Resolved leet8845

    (@leet8845)


    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

Viewing 1 replies (of 1 total)
  • Thread Starter leet8845

    (@leet8845)

    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!

Viewing 1 replies (of 1 total)
  • The topic ‘Widget Logic – How to exclude children and grandchilren’ is closed to new replies.