WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Widget Logic] Conditional date tags?

[Plugin: Widget Logic] Conditional date tags?

Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Author alanft
    Member

    @alanft

    http://codex.wordpress.org/Conditional_Tags#A_Date_Page seems to say that it’s only use is to indicate a date-based archive page (like a year, month or day) list of posts is showing.

    are you actually after a widget for an individual post dated in a specific range, or are you after a specific date-range in the archive list? cos that can be done, just not with is_date

    cozbaldwin
    Participant

    @cozbaldwin

    I think I, too, am looking for what Benz1 wants: A widget that (hopefully via Widget Logic) will only display in the sidebar for a certain period of time and disappear once a date’s been reached.

    For instance, a Text widget with a home-made advertisement in it which the client’s paid to have displayed until February 14th. I’d love for Widget Logic to know when it’s February 14th and stop displaying the content rather than try to remember to log in and deactivate the widget myself.

    I’ve actually gone ahead and had a widget developed to do this. Just beta testing now. Give me a few days and it should be available on the repository.

    cozbaldwin
    Participant

    @cozbaldwin

    Wonderful. Definitely post an update here when it’s ready. I’ll be using it. But I’d still love to know if Widget Logic can already do this somehow. If not, alanft, consider this a recommendation to add the capability to your most excellent plugin.

    zestylemon
    Member

    @zestylemon

    I too wish dates could be used in Widget Logic. Any word from the developer as to whether this is on the roadmap or not?

    Benz1: Did your widget pass beta testing? Have you added it to the repository?

    Plugin Author alanft
    Member

    @alanft

    something like

    return mktime(0, 0, 0, 7, 1, 2011) < time() && time() < mktime(0, 0, 0, 7, 31, 2011)

    should only show in July 2011. mktime params are h/m/s/mon/day/year

    cozbaldwin
    Participant

    @cozbaldwin

    Yes! Although, that doesn’t work.
    (even with the word “return” taken out, as I don’t think that should be there in the first place)

    Lynda
    Member

    @lyndasu

    Use the date function. For example, I programmed a widget to only display if the day is Wednesday:

    date("l")=='Wednesday'

    Any of the PHP date formats should work here.

    cozbaldwin
    Participant

    @cozbaldwin

    Hmmm. Well, not knowing php too well, how would you use the php dates to say “if date is at least May 18 2011 AND is not after May 31 2011”?

    Lynda
    Member

    @lyndasu

    oh, you want to use the date of the post to conditionally display widgets? My use is for the current date to conditionally display widgets.

    I think your way would require another loop to pull out the post date, which sounds messy, if not impossible with this plugin. A better way to do it might be to write some PHP to call for the post date and do the calculations in the header and then pass the resulting variable along to the widget.

    For example, you could grab the post month, day, year and then write an if statement assigning a specific variable value between the dates in question, then use that in the widget box ($myvariable == 'yes')

    That will take some thought though. I’m thinking out loud here in case anyone with more time than I do right now wants to try it.

    cozbaldwin
    Participant

    @cozbaldwin

    No, no. Sorry. To reiterate what I’m looking for, and I think the original poster is looking for: A widget that will only display in the sidebar for a certain period of time and disappear once a date’s been reached. (A great tool to have for privately paid ads)

    Lynda
    Member

    @lyndasu

    Ah! Okay, that is doable! This is what you want to put in the widget logic box:

    date("m.d.y") > '05.01.11' && date("m.d.y") < '05.15.11'

    Change 05.01.11 to the start date and 05.15.11 to the end date. Written this way, you need to enter a mm.dd.yy format for the date.

    I hope this helps!

    cozbaldwin
    Participant

    @cozbaldwin

    Well the good news is that solution, like the mktime solution that alanft suggested, doesnt cause any error. The bad news is, neither of them print the widget.

    I even went as far as to use the most complete, specific formatting possible in order to test it:
    date("D M j G:i:s T Y") > 'Wed May 18 14:18:00 EDT 2011' && date("D M j G:i:s T Y") < 'Wed May 18 14:19:00 EDT 2011'

    I changed the time zone to make sure it wouldnt be using my server’s time zone. I changed it to daylight time, etc. It just doesn’t print anything. I guess something in the widget code itself has to be added to recognize this stuff?

    I just went looking for another logic extender, but I can’t find any except for “Dynamic Widgets” — however from the screenshots, it appears as though you cannot set specific date ranges for specific widgets. The most specific I could get is setting a date range for all Text Widgets on a certain page. 🙁

    This seems like it would be relatively easy for the Widget Logic programmer to incorporate. I hope he/she does soon.

    cozbaldwin
    Participant

    @cozbaldwin

    I am interested to see if date("l")=='Wednesday' and date("l")=='January 2011'
    will work, but I can’t exactly test that without waiting a month.

    Lynda
    Member

    @lyndasu

    The more you include for the date to capture, the more likely it will be that you’ll screw up the value so I would definitely recommend less is more.

    I would not recommend testing using a one minute difference, even if you know the server time. It’s just too hard to catch the “right time” with so little room for error.

    I tested this on my blog before I replied to you and it worked exactly as expected. What date values did you put in to start with the original code above?

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘[Plugin: Widget Logic] Conditional date tags?’ is closed to new replies.