WordPress.org

Ready to get started?Download WordPress

Forums

AM Events
[resolved] Remove end date if it's same as start date (3 posts)

  1. brian.clarke
    Member
    Posted 2 months ago #

    Firstly, let me state that this plugin is great. Nice and clean. However, I'm trying to figure out how to remove the start or end date if the event is only a single day. For example, I would prefer it to output July 4 instead of July 4 - July 4. I was combing through the code, but I'm pretty lost when it comes to PHP.

    Any ideas on how to accomplish this?

    I still want events that span more than a day to output the start and end dates too.

    If the event calendar could look like this, that would be great:
    July 4
    August 3 - August 10
    September 1 - September 2

    https://wordpress.org/plugins/am-events/

  2. Atte Moisio
    Member
    Plugin Author

    Posted 2 months ago #

    Hi,

    Sorry for taking so long to answer. Anyway, if you are displaying the events in a page template, it is as easy as using a conditional statement to check if the dates are equal and displaying based on that.

    However, if you are using the widget, then it's not so easy. I'll probably be adding some kind of conditional tags for the widget in the future. Meanwhile, if you want, you could do the following:

    in widget-upcoming-events.php in function process_shortcode( $m ) replace:

    case 'end-date':
      $enddate = am_get_the_enddate();
      $format = $format === '' ? "m/d/Y H:i" : $format;
      return $m[1] . date_i18n( $format, strtotime($enddate) ) . $m[6];

    with:

    case 'end-date':
      $enddate = am_get_the_enddate();
      $format = $format === '' ? "m/d/Y H:i" : $format;
      if (am_get_the_startdate() !== am_get_the_enddate()) {
        return $m[1] . date_i18n( $format, strtotime($enddate) ) . $m[6];
      }
  3. Atte Moisio
    Member
    Plugin Author

    Posted 2 months ago #

    Hey again,

    You can ignore the instructions in the previous post, I've just updated the plugin and included the conditional tags :)

    Example of displaying end date only if it not the same as the startdate:

    [start-date format='D d.m.Y H:s']
    [if cond='startdate-not-enddate']
     - [end-date format='D d.m.Y H:s']
    [/if]

Reply

You must log in to post.

About this Plugin

About this Topic