• erau-simon

    (@erau-simon)


    First off, great job – this is an ingenious plugin!

    I have a few widgets set up with the following logic. I intend to use it as a simple solution for internal ads. I only want one maximum widget to display.

    is_single() && in_category('Topic-A') && define('ad_displayed', true)

    is_single() && in_category('Topic-B') && define('ad_displayed', true)

    If a post is in both Category-A and Category-B, the first widget above should show, and the second shouldn’t.

    I feel like I’ve tried every possible way to accomplish this. The method above seems to be the most foolproof. The last condition, PHP’s define returns true the first time it is set, and it returns false subsequent attempts. Strangely, with Widget Logic, the constant above gets defined, but the widget won’t show.

    I’ve also tried the same kind of logic using variables, including superglobals.

    I hope this makes sense. Please let me know if I can clarify anything. Any help is very appreciated!

    https://wordpress.org/plugins/widget-logic/

Viewing 6 replies - 1 through 6 (of 6 total)
  • alanft

    (@alanft)

    you can use statements that are full PHP code blocks with an explicit ‘return’. So you should be able to try things like this…

    global $MY_ADS; $MY_ADS++; return (is_single() && in_category('Topic-A'));

    (note the final semi-colon), and

    global $MY_ADS; $MY_ADS++; return (is_single() && in_category('Topic-B') && ($MY_ADS<2));

    have a go

    Thread Starter erau-simon

    (@erau-simon)

    Unfortunately, even the following example won’t work.

    global $MY_ADS; $MY_ADS++; return ($MY_ADS < 2);

    Does that work for you?

    Thread Starter erau-simon

    (@erau-simon)

    I should be able to set a couple widgets with that logic and just the first one would show. However, neither one is showing for me.

    alanft

    (@alanft)

    hmm. perhaps not, sorry.

    i’d be interested to know if it made a difference changing the ‘load logic’ point while using that style code. And ultimately if the ‘developer’ version worked with code like this too.

    (I made some big changes in the dev version but I’m finding it hard to commit to the changes because it’s hard to get anyone to beta test)

    Thread Starter erau-simon

    (@erau-simon)

    Sadly, other load logic settings don’t make it evaluate correctly.

    I appreciate your help. I’ll give the developer version a try on a test site.

    Thread Starter erau-simon

    (@erau-simon)

    On a different WP 4.1.1 instance, with the developer version, the Widget Logic field is emptied every time I save widget settings.

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