• I cant get widget logic to work as i want.

    i want to view a widget on siderbar if:
    1. we view a post in one of the categories 1,2,3
    OR
    2. we view one of the categories 1,2,3
    OR.
    3. we view the page 575

    so i made the following query for widget logic:
    ((is_single(array(in_category(array(1,2,3))))) || is_category(array(1,2,3)) || is_page(575))

    the is single does not work, but the other 2 conditions (is_category,is_page) work perfectly.

    what i’m doing wrong with is_single?

    thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • I think this is what you want:

    ((is_single() && in_category(array(1,2,3))) || is_category(array(1,2,3)) || is_page(575))

    Thread Starter theodion

    (@theodion)

    it doesnt work ??

    i converted all my queries like the above ^^ but (is_single() && in_category(array(1,2,3))) does not work…

    1.

    ((is_single() && in_category(array(6,35,36,37,38))) || is_category(array(6,35,36,37,38)) || is_page(575))

    2.
    ((is_single() && in_category(array(24,47,48,50,51))) || is_category(array(24,47,48,50,51)) || is_page(563))

    3.
    ((is_single() && in_category(array(23,27,28,29,30,31,52,53,54))) || is_category(array(23,27,28,29,30,31,52,53,54)) || is_page(478))

    You may need to supply the post ID in the in_category call.

    Thread Starter theodion

    (@theodion)

    i already tried that. no luck.

    come one guys… no one can help me solve this?

    Thread Starter theodion

    (@theodion)

    You may need to supply the post ID in the in_category call.

    i tried in_category(6,770)

    View the widget menu if the post with id 770 belongs to category 6.
    this is true but the widget does not appear…

    Thread Starter theodion

    (@theodion)

    to clear the above:

    i’m viewing the post 770 which belongs to category 6

    i supplied widget custom menu with this in_category(6,770)

    and the widget does not appear…

    You say the widget shows when is_category is true, and when is_psge(575) is true, so narrow down the part that is not working. First try:

    ((true && in_category(array(6,35,36,37,38))) || is_category(array(6,35,36,37,38)) || is_page(575))

    If that works, then is_single() is returning false. If not, in_category(…) is returning false.

    https://codex.www.ads-software.com/Template_Tags/in_category

    in the case of calling in_category with 2 parameters, the 2nd one is the post ID, so in_category(6,770) will be always false or always true, regardless of what post/page/etc you are looking at.

    if you are absolutely sure that post 770 is in category 6, then that should always be true and that widget will always show. so i can’t explain what you are seeing.

    the form is_single() && in_category(array(1,2,3)) should do what you want. if it’s not, see if it IS working when you switch to a default theme – just to check if the theme code is interfering with WP stuff behind the scenes that alters the evaluation of those conditional tag.

    another suggestion – try supplying the category slug instead of the ID

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘widget logic help’ is closed to new replies.