markdown Shortcode - 现代部落的活动日历 - WordPress插件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Shortcode - 现代部落的活动日历 - WordPress插件相关的知识,希望对你有一定的参考价值。

# How to use this shortcode

Here is info on how to use and customize the events shortcode for The Events Calendar by Modern Tribe WordPress plugin. The events shortcode displays a list of your events wherever you want them to appear on your site. 

### All parameters of the shortcode:

`[my_events cat='art-gallery' offset='1' limit='3' featured='yes' past='yes']`

For example of a specific use, here is the shortcode to show next 8 events in the category `festival`:

`[my-events cat='festival' limit='8']`

## Basic shortcode

`[my-events]`

## Shortcode Options
**cat**

Represents single event category. Do not use multiple categories in the same shortcode.

`[my-events cat='festival']`

**offset**

To skip or pass over events (for example, if you pull in the first event elsewhere on the page). Default is `0`.

`[my-events cat='festival' offset='1']`

**limit**

Total number of events to show. Default is all upcoming events.

`[my-events cat='festival' limit='3']`

**featured**

Show large image above text

`[my-events cat='festival' featured='yes']`

**past**

Show outdated events (ie. events that have already happened)

`[my-events cat='festival' past='yes']`
# Display events the way you need to

### Use case

This shortcode is useful to offset events or show event date rather than date posted. The shortcode can be used anywhere that shortcodes can be: on a WordPress page, post, widget, etc. 

You can, of course, add to the shortcode to make it how you like.

### References

For WP Query: https://codex.wordpress.org/Class_Reference/WP_Query

For past events parameter: https://support.theeventscalendar.com/666307-Using-tribe_get_events
//* Add Shortcode [my_events cat='art-gallery' offset='1' limit='3' featured='yes' past='yes']
add_shortcode( 'my-events', 'my_events_function' );
function my_events_function( $atts ){

  // Add shortcode attributes
  $a = shortcode_atts( array(
      'cat' => '',
      'offset' => 0,
      'limit' => -1,
      'featured' => '',
      'past' => '',
  ), $atts );
    
	// Variables for the attributes
  $my_events_cat = "{$a['cat']}";
  $my_events_offset = "{$a['offset']}";
  $my_events_limit = "{$a['limit']}";
  $my_events_featured = "{$a['featured']}";
  $my_events_past = "{$a['past']}";
	
	// Variables for featured layout
	if( $antioch_events_featured === 'yes' ) {
		$my_events_class = 'antioch-events-featured';
		$my_events_content = 'yes';
		$my_events_img_size = 'et-pb-post-main-image';
	} else {
		$my_events_class = 'antioch-events';
		$my_events_content = '';
		$my_events_img_size = 'thumbnail';
	}
	
	// Variables for past events
	if( $my_events_past === 'yes' ) {
		$my_events_eventDisplay = 'past';
	} else {
		$my_events_eventDisplay = 'upcoming';
	}	

	// Query arguments if no category is entered
	if ( empty( $antioch_events_cat ) ) {
		$args = array( 
			'post_type' 		=> 'tribe_events', 
			'posts_per_page' => $my_events_limit,
			'eventDisplay' 	=> $my_events_eventDisplay, // this parameter is from TEC plugin, must have to show past events
			'offset' 		=> $my_events_offset,
		);

	// Query arguments if category is entered
	} else {		
		$args = array( 
			'post_type' 		=> 'tribe_events', 
			'posts_per_page' => $my_events_limit,
			'eventDisplay' 	=> $my_events_eventDisplay,
			'offset' 		=> $my_events_offset,
			'tax_query' 		=> array( array(
				'taxonomy' 		=> 'tribe_events_cat',
				'field'    		=> 'slug',
				'terms'    		=> $my_events_cat,
			), ),
		);
	}
	
	// The loop
	$loop = new WP_Query( $args );
	
		$data = ''; // init
		$data .= sprintf( '<div class="clearfix %s">', $my_events_class );				
		
		while ( $loop->have_posts() ) : $loop->the_post();
					
			// Get Featured Image for later, otherwise get placeholder image
			$thumbnail = get_the_post_thumbnail( $loop->ID, $my_events_img_size );

			// If no Featured Image and Featured layout, get large placeholder image for later
			if ( empty( $thumbnail ) && $my_events_featured != 'yes' ) 
				$thumbnail = '<img src="/wp-content/uploads/placeholder-150x150.jpg" alt="Placeholder" width="150" height="150">';

			// If no Featured Image and not Featured layout, get small placeholder image for later
			if ( empty( $thumbnail ) && $my_events_featured === 'yes' ) 
				$thumbnail = '<img src="/wp-content/uploads/placeholder-400x250.jpg" alt="Placeholder" width="400" height="250">';

    	$data .= sprintf( '<article class="et_pb_post clearfix">' );
		  $data .= sprintf( '<div class="et_pb_image_container"><a href="%s" title="See event details">%s</a></div>', get_permalink(), $thumbnail ); 
		    
			// If Featured layout, display title, date, content
			if( $antioch_events_featured === 'yes' ) {
			    $data .= sprintf( '<h4 class="entry-title"><a href="%s" title="See event details">%s</a></h4>', get_permalink(), get_the_title() ); 
			    $data .= sprintf( '<p class="event-meta"><a href="%s" title="See event details">%s</a></p>', get_permalink(), tribe_events_event_schedule_details() ); 
			    $data .= sprintf( '<div class="post-content"><p>%s</p><a href="%s" class="more-link">Read More</a></div>', get_the_excerpt(), get_permalink() ); 
			}
		    
			// If not Featured layout, display date, title
			if( $my_events_featured != 'yes' ) {
			    $data .= sprintf( '<p class="event-meta">%s</p>', tribe_events_event_schedule_details() ); 
			    $data .= sprintf( '<h4 class="entry-title">%s</h4>', get_the_title() ); 
			}
			
			$data .= sprintf( '</article>' ); // END et_pb_post class
			
		endwhile; 
	
		$data .= sprintf( '</div>' ); // END my-events class
				
		return $data; // spits data out on the page
	
	wp_reset_postdata();
	
} // END my_events_function
[ file under: Notes ]

## The Events Calendar
*Pull in events using various options.*

Shortcode options: 

`[my_events cat='art-gallery' offset='1' limit='3' featured='yes' past='yes']`

Here is info on how to use and customize the shortcode:
- https://gist.github.com/JennyWren/6d0db29237e2d231623686938128305d#file-how-to-use-md

以上是关于markdown Shortcode - 现代部落的活动日历 - WordPress插件的主要内容,如果未能解决你的问题,请参考以下文章

markdown 现代WordPress生产工作流程

markdown 现代的影子

(现代)React 功能组件可以在外部公开有状态方法吗?

markdown React文档中的现代JavaScript

markdown React文档中的现代JavaScript

markdown 缺少Angular 2和现代设计模式的介绍