• Resolved andre77

    (@andre77)


    WordPress generates the following message: “Warning: in_array() expects parameter 2 to be array, null given in C:\wamp\…\wp-content\themes\themename\sidebar.php on line 22” (line 22 being the first row in the code)

    And here below you can see the code:

    if (is_page(25) || in_array(“25”,$post->ancestors)){ ?>
    <?php dynamic_sidebar( ‘sidebarmenu_welcome’ ); ?>

    <?php } else { ?>
    <?php dynamic_sidebar( ‘sidebarmenu_other’ ); ?>
    <?php } ?>

    (this code checks if I am on a certain page, or if the current page is an ancestor of that specific page)

    The webpage I am working on has both static pages, and a blog. The above code works fine on all static pages, but on the Blog page, this error message comes up. And then I have configured the: “Front Page” and “Blog Page” through the “reading settings” in the Admin Panel.

    i.e. for some reason this code doesnt work when displaying “posts” instead of pages.

    Can you help me correct this code? So it works when both pages and posts are displayed.

Viewing 16 replies (of 16 total)
  • Thread Starter andre77

    (@andre77)

    Hey David!

    Sorry for the late reply, been away for some days. Using custom meta fields is an idea that I didnt think of. That could give the administrative users more flexibility, but if such a high flexibility isn’t needed, then I guess it would also result in a slightly more administrative work – as every new sub page would need have to have a custom field assigned to it to display the appropriate sidebar.

    But I guess the possibilities are quite many if you know all the ropes of WordPress / PHP.

    But the initial question/problem has been solved – thanks to your good effort 🙂

    Kind regards,

    André

Viewing 16 replies (of 16 total)

The topic ‘Error message= "Warning: in_array() expects parameter 2 to be array, null given"’ is closed to new replies.