• Would be great if you could add the shortcode [events_grid] in a future release!

    In the meantime I took the [events_list] code and quickly adapted it:

    add_shortcode('events_grid', 'em_get_events_grid_shortcode');
    
    function em_get_events_grid_shortcode($args, $format='') {
    	$args = (array) $args;
    	$args['ajax'] = isset($args['ajax']) ? $args['ajax']:(!defined('EM_AJAX') || EM_AJAX );
    	$args['format'] = ($format != '' || empty($args['format'])) ? $format : $args['format']; 
    	$args['format'] = html_entity_decode($args['format']); //shortcode doesn't accept html
    	$args['limit'] = isset($args['limit']) ? $args['limit'] : get_option('dbem_events_default_limit');
    	if( !empty($args['id']) ) $args['id'] = rand();
    	if( empty($args['format']) && empty($args['format_header']) && empty($args['format_footer']) ){
    		ob_start();
    		em_locate_template('templates/events-grid.php', true, array('args'=>$args));
    		$return = ob_get_clean();
    	}else{
    		$args['ajax'] = false;
    		$pno = ( !empty($args['pagination']) && !empty($_GET['pno']) && is_numeric($_GET['pno']) )? $_GET['pno'] : 1;
    		$args['page'] = ( !empty($args['pagination']) && !empty($args['page']) && is_numeric($args['page']) )? $args['page'] : $pno;
    		$return = EM_Events::output( $args );
    	}
    	return $return;
    }

    I didn’t check all the code logic, so probably something is missing or redundant, but for what I needed it seems working. 😸

    I hope it helps others!

    • This topic was modified 1 year, 5 months ago by rebelc0de.
Viewing 9 replies - 1 through 9 (of 9 total)
  • I’ve tried the above using WP Code and inserted it into the header. But it shows an error in the array command. Is this correct way of adding the code. Please can you advise.

    Thread Starter rebelc0de

    (@rebelc0de)

    I also use WP Code, I started with its example of a shortcode and added my code instead. The location is “everywhere”.

    Improved code:

    add_shortcode('events_grid', 'em_get_events_gridmode_shortcode');
    
    function em_get_events_gridmode_shortcode($args, $format='') {
    	$args = (array) $args;
    	$args['ajax'] = isset($args['ajax']) ? $args['ajax']:(!defined('EM_AJAX') || EM_AJAX );
    	$args['format'] = ($format != '' || empty($args['format'])) ? $format : $args['format']; 
    	$args['format'] = html_entity_decode($args['format']); //shortcode doesn't accept html
    	$args['limit'] = isset($args['limit']) ? $args['limit'] : get_option('dbem_events_default_limit');
    	if( !empty($args['id']) ) $args['id'] = rand();
    	if( empty($args['format']) && empty($args['format_header']) && empty($args['format_footer']) ){
    		ob_start();
    		// add default grid formats
    		if( empty($args['format']) ){
    			$args['format'] = get_option( 'dbem_event_grid_item_format' );
    		}
    		if( empty($args['format_header']) ){
    			$args['format_header'] = get_option('dbem_event_grid_format_header');
    		}
    		if( empty($args['format_footer']) ){
    			$args['format_footer'] = get_option('dbem_event_grid_format_footer');
    		}
    		 //if successful, this template overrides the settings and defaults, including search
    		em_locate_template('templates/events-grid.php', true, array('args'=>$args));
    		$return = ob_get_clean();
    	}else{
    		$args['ajax'] = false;
    		$pno = ( !empty($args['pagination']) && !empty($_GET['pno']) && is_numeric($_GET['pno']) )? $_GET['pno'] : 1;
    		$args['page'] = ( !empty($args['pagination']) && !empty($args['page']) && is_numeric($args['page']) )? $args['page'] : $pno;
    		$return = EM_Events::output( $args );
    	}
    	return $return;
    }

    rebelc0de I have finally got to this. It was way out of my comfort zone. But I’ve got it working. Many many thanks.

    Thread Starter rebelc0de

    (@rebelc0de)

    Awesome, happy to help! I hope devs will integrate it with more options, the grid is very very useful. 🧙‍♀️

    ADVICE
    If you are not familiar with code you should make tests like this in local, before risking to destroy your website. I use WP Local: in 1 click you can create a WP test site (or more). 🪅

    Hey, another thanks for doing this. Works like a charm. It’s a shame you had to do this because events_list view=”grid” doesn’t work. Hopefully they will either fix that or take your idea and have a separate events_grid shortcode (much better in my opinion).

    Thread Starter rebelc0de

    (@rebelc0de)

    It’s great when people appreciate 😸

    Btw I cannot find view="grid" in the docs:
    https://wp-events-plugin.com/documentation/shortcodes/

    From my code searches, they have not yet implemented any shortcode for the grid view.

    Thank you @rebelc0de , works great !

    clcudebec

    (@clcudebec)

    This is SO CLOSE to what I need! Is there anyway to add the search bar function that would work alongside this? Thanks for sharing!

    Thanks for your code!!!

    • This reply was modified 8 months, 2 weeks ago by juas_ma.
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘New shortcode [events_grid]’ is closed to new replies.