• Hi

    I really like your plugin and would like to use this for my next project. However, I don’t know if vsel can handle this scenario:

    On the startpage I need to list 4 events, the latest from each of 4 categories, in correct date order. Can this be done with the shortcodes? I have tried to accomplish this with custom css targeting each category like this:

    .category-name:not(.first-child)

    But it doesn’t work… any insight or help at hand?

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 27 total)
  • Thread Starter Sinkadus

    (@niwin)

    Hmm if it would be easy-ish to add a new shortcode, this one might do the trick:

    posts_per_category=”1″

    together with multiple categories:

    [vsel event_cat=”your-category-slug-1, your-category-slug-2″ posts_per_category=”1″]

    What do you think, might be useful?

    Plugin Author Guido

    (@guido07111975)

    Hi,

    If you want the most recent event from every category, you must add multiple shortcodes, one for every category.

    
    [vsel event_cat="your-category-slug-1" posts_per_page="1" pagination="false"]
    [vsel event_cat="your-category-slug-2" posts_per_page="1" pagination="false"]
    

    It’s not possible the way you suggest, because that’s not how the WP query works.

    I don’t recommend adding multiple shortcodes on the same page (can cause conflict in the queries) but if you do, at least disable the pagination of every shortcode, with pagination="false".

    Guido

    Thread Starter Sinkadus

    (@niwin)

    I see…. well, I can’t do multiple shortcodes with each category, because I need them to be in date order. If I do multiple shortcodes, the four events would list like so (example):

    cat1: august 11 (first upcoming date for this cat)
    cat2: july 13 (first upcoming for this cat)
    cat3: sept 1 (first upcoming for this cat)
    cat4: june 28 (first upcoming for this cat)

    But I would like the four events to be in date order:

    june 28: cat4
    july 13: cat2
    aug 11: cat1
    sept 1: cat4


    And the new shortcode I proposed, would that not work, or be too complicated to implement?

    Plugin Author Guido

    (@guido07111975)

    Hi,

    You can seperate the 4 shortcodes with a heading (the name of every category). That way date order is not necessary.

    Your request means I have to build a custom query for this. Takes time. Besides this, I only add new features that will be commonly used, and I think this new query is not something that will be used by many users. Sorry.

    Guido

    Thread Starter Sinkadus

    (@niwin)

    Yeah, but I need them to be in one feed, so splitting them up won’t do.

    But I understand ofc, this scenario is probably pretty rare, so it makes sense that you put those hours elsewhere.

    I’ll look around and see if I can find some other solution to this.

    Many thanks for taking the time to answer and looking into this! My 5 star review stands firm ??

    Thread Starter Sinkadus

    (@niwin)

    Hi, just a final word. I haven’t found any reliable event plugin that can limit posts per category, in accordance with my need. So I will have to change my plan.

    However, if you do will find the time to build this new custom query for the shortcode posts_per_category=”1″, your plugin would be the only one that could do this. Maybe that not enough of a carrot to put in the hours for a shortcode that you don’t think people will use anyway… but still, just wanted to let you know.

    Cheers!

    Plugin Author Guido

    (@guido07111975)

    Hi,

    Even if you have found a plugin that can do this you cannot use this instead of VSEL, because all event plugins have their own set of custom fields for event data. In that case you have to re-add or change all existing events. Guess you already know that.

    I will look into it. Maybe create a custom snippet for you.
    Which event data do you want to display? Title, date, location, featured image, more?
    The first upcoming events?
    You are able to do the syling yourself?

    Guido

    Thread Starter Sinkadus

    (@niwin)

    Yes, I do realize this. Thats why I have not created any content yet, so if/when I find a plugin that can do this, I can use that plugin right from the start.

    If you do – that would be truly amazing. Event data would only be Title, Date and Featured image for this particular list view. Regular content will ofc be displayed on single events.

    All events will be same location, so this will not be needed to display, at least not in list view.

    Fingers crossed (but ofc understand if this does not get your priority)

    Thread Starter Sinkadus

    (@niwin)

    Ah yes, as long as there are proper classes, I can do styling myself.

    Plugin Author Guido

    (@guido07111975)

    Hi @niwin

    Have created this snippet for you. You can add this with the Code Snippets plugin. After adding you can use the shortcode [vsel-custom] to display the events. Questions? Please let me know ??

    // vsel custom shortcode
    // return first upcoming event from every category
    function vsel_custom_shortcode() {
    	// initialize output
    	$output = '';
    	// start main container
    	$output .= '<div id="vsel">';
    
    	// categories query
    	$cat_args = array(
    		'order' => 'ASC',
    		'orderby' => 'name',
    		'taxonomy' => 'event_cat',
    		'hide_empty' => 1
    	);
    	$cats = get_categories( $cat_args );
    	foreach ($cats as $cat) :
    		// timestamp today
    		$current_date = current_datetime();
    		$var = $current_date->setTime( 0, 0, 0, 0);
    		$today = $var->getTimestamp()+$var->getOffset();
    
    		// events query
    		$meta_query = array(
    			'relation' => 'AND',
    			array(
    				'key' => 'event-date',
    				'value' => $today,
    				'compare' => '>=',
    				'type' => 'NUMERIC'
    			)
    		);
    		$query_args = array(
    			'post_type' => 'event',
    			'tax_query' => array(
    				array(
    					'taxonomy' => 'event_cat',
    					'field' => 'term_id',
    					'terms' => $cat->term_id,
    					'include_children' => false
    				),
    			),
    			'post_status' => 'publish',
    			'ignore_sticky_posts' => true,
    			'meta_key' => 'event-start-date',
    			'orderby' => 'meta_value_num menu_order',
    			'posts_per_page' => 1,
    			'meta_query' => $meta_query
    		);
    		$query = new WP_Query( $query_args );
    
    		if ( $query->have_posts() ) :
    			while( $query->have_posts() ): $query->the_post();
    
    			// start event container
    			$output .= '<div id="event-'.get_the_ID().'" class="vsel-content">';
    				// start event details section
    				$output .= '<div class="vsel-meta vsel-meta-left" style="width:36%;">';
    					// title
    					$output .=  '<h3 class="vsel-meta-title"><a href="'.get_permalink().'" rel="bookmark" title="'.get_the_title().'">'.get_the_title().'</a></h3>';
    					// date
    					$start_date_timestamp = get_post_meta( get_the_ID(), 'event-start-date', true );
    					$end_date_timestamp = get_post_meta( get_the_ID(), 'event-date', true );
    					$output .= '<div class="vsel-meta-date">';
    					$output .= '<span>'.wp_date( 'j F', esc_attr($start_date_timestamp) ).'</span>';
    					if ($end_date_timestamp > $start_date_timestamp) {
    					$output .= ' - ';
    					$output .= '<span>'.wp_date( 'j F', esc_attr($end_date_timestamp) ).'</span>';
    					}
    					$output .= '</div>';
    					// category
    					$output .= '<div class="vsel-meta-cats">'.esc_attr($cat->name).'</div>';
    				// end event details section
    				$output .= '</div>';
    				// start event info section
    				$output .= '<div class="vsel-image-info vsel-image-info-right" style="width:60%;">';
    					// featured image
    					$output .=  '<a href="'.get_permalink().'">'.get_the_post_thumbnail( get_the_ID(), 'post-thumbnail', array( 'class' => 'vsel-image vsel-image-right', 'style' => 'max-width:20%', 'alt' => get_the_title() ) ).'</a>';
    				// end event info section
    				$output .= '</div>';
    			// end event container
    			$output .= '</div>';
    
    			endwhile;
    		endif;
    		// reset post data
    		wp_reset_postdata();
    	endforeach;
    	// end main container
    	$output .= '<div>';
    	// return output
    	return $output;
    }
    add_shortcode('vsel-custom', 'vsel_custom_shortcode');
    Thread Starter Sinkadus

    (@niwin)

    Amazing! It does create a list of 4 events, one from each category! Only one problem, the events are not sorted by event date. I tried changing to this:

    // categories query
    	$cat_args = array(
    		'order' => 'ASC',
    		'orderby' => 'date',
    		'taxonomy' => 'event_cat',
    		'hide_empty' => 1
    	);

    But that didn’t fix it, so something else needed?

    Thread Starter Sinkadus

    (@niwin)

    Sorry, I meant that I tried to change orderby to ‘event-date’ (not ‘date’)

    Plugin Author Guido

    (@guido07111975)

    Hi,

    Hm, understand you but you’re asking too much. First query is to get all event cats, second query is to get first event of every cat. Ordering is by category, because that’s the main query. Right now no idea how to change that into ordering by event date. Have to think about this a little more..

    Guido

    Thread Starter Sinkadus

    (@niwin)

    Aha, that explains it. With code, there is always puzzles to solve. I do hope you like puzzles… ??

    And if this is indeed unsolvable, I’m still very grateful for the snippet you provided ??

    Plugin Author Guido

    (@guido07111975)

    You cannot separate the categories with on top the cat name as heading? IMO it’s not very logical to list events the way you want without separation.

    Guido

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘Limit to latest in each category’ is closed to new replies.