• Resolved Plastikschnitzer

    (@plastikschnitzer)


    Hi,
    is there a way to hide the map, if there are no events available? At the moment it shows as a grey box, it would be nice to hide it in these cases.

    Best regards,
    Plastikschnitzer

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hi Plastikschnitzer,

    It could be possible with CSS or custom development. Can you share the page URL where there are no events and the grey box is showing so I could take a look?

    Thanks,
    Imran

    Thread Starter Plastikschnitzer

    (@plastikschnitzer)

    Hi Imran,

    here is the link: Testing page no events

    Best regards,
    Plastikschnitzer

    Plastikschnitzer,

    You can try adding this JavaScript code in your website:

    jQuery(document).ready(function($) {
    
      $('.em-locations-map').each(function(i, el) {
        var $mapEm = $(el).find('em');
    
        if ( $mapEm.length ) {
          if ( $mapEm.text() == 'No locations found' ) {
            $(el).closest('.em-location-map-container').hide();
          }
        }
      });
    
    });

    If you’re not sure how to add the JS code in your site, perhaps this would help: https://www.ostraining.com/blog/wordpress/custom-js/

    Thanks,
    Imran

    @plastikschnitzer Just to check something… Are the maps working on other pages?

    Thread Starter Plastikschnitzer

    (@plastikschnitzer)

    @caimin_nwl Yes sure, maps are working on other pages 😉

    @emranemranx Thank you very much for the code, I inserted it into the page linked above, but unfortunately its not working.

    Another question: There a text statement from Events Manager which shows up if there are no locations, but it does not show up if you use the shortcode for [locations_map] shortcode, right?!

    Best regards,
    Plastikschnitzer

    Plastikschnitzer,

    Please try out this JavaScript code:

    jQuery(document).ready(function($) {
    
      // if ( $('body').hasClass('page-id-295') ) {
        runAfterAjaxComplete();
        $(document).ajaxComplete(runAfterAjaxComplete);
        $(window).load(runAfterAjaxComplete);
      // }
    
      function runAfterAjaxComplete() {
        $('.em-locations-map').each(function(i, el) {
          var $mapEm = $(el).find('em');
    
          if ( $mapEm.length ) {
            if ( $mapEm.text() == 'No locations found' ) {
              $(el).closest('.em-location-map-container').hide();
            }
          }
        });
      }
    
    });

    Regarding your another question, yes, the text statement doesn’t show up when you use the shortcode.

    Thanks,
    Imran

    An easier way to do this would be to use one of the conditional location placeholders. Like this_

    {has_location} map stuff here {/has_location}

    http://wp-events-plugin.com/documentation/conditional-placeholders/

    Thread Starter Plastikschnitzer

    (@plastikschnitzer)

    Thank you @emranemranx the updated code is working. Bad side is the code is only executed after DOM is loaded which means the box shows up first and then disappears.

    Also thank you @caimin_nwl – I totally forgot about this simple solution which is already built in and already in use in many other places …

    Question: How can I use conditional placeholders in posts or pages? I mean I could create a custom page template which includes the map with conditional placeholders before or after the content – but is there another simple way?

    You mean you want to use them directly in the PHP template?

    Thread Starter Plastikschnitzer

    (@plastikschnitzer)

    No, in pages, posts or widgets.

    Try this:

    {has_location} #_LOCATIONMAP {/has_location}

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Hide map if there are no events’ is closed to new replies.