php 事件短代码 - 事件日历WordPress插件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 事件短代码 - 事件日历WordPress插件相关的知识,希望对你有一定的参考价值。
//* Add Shortcode [twc_events events_category_slug="featured" number="3" grid="true"]
add_shortcode( 'twc_events', 'twc_events_function' );
function twc_events_function( $atts ){
// Add shortcode attributes
$a = shortcode_atts( array(
'events_category_slug' => 'featured',
'number' => 3,
'grid' => FALSE,
), $atts );
// Variables for the attributes
$twc_events_category_slug = "{$a['events_category_slug']}";
$twc_events_per_page = "{$a['number']}";
$twc_events_grid = "{$a['grid']}";
// Variables for grid (3 column) or non-grid (2 column)
if( $twc_events_grid == TRUE ) {
$twc_events_grid_class = 'twc_column_1_3';
$img_size = 'events-grid';
}
if( $twc_events_grid != TRUE ) {
$twc_events_grid_class = 'twc_column_1_2';
$img_size = 'events-non-grid';
}
// Query arguments
$args = array(
'post_type' => 'tribe_events',
'posts_per_page' => $twc_events_per_page,
'tax_query' => array( array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => $twc_events_category_slug,
), ),
);
// The loop
$loop = new WP_Query( $args );
$data = ''; // init
$data .= sprintf( '<div class="et_pb_blog_grid clearfix styled-events">' );
while ( $loop->have_posts() ) : $loop->the_post();
// Get Featured Image, otherwise show placeholder
$thumbnail = get_the_post_thumbnail( $loop->ID, $img_size );
if ( empty( $thumbnail ) ) $thumbnail = '<img src="/wp-content/uploads/twc_placeholder.jpg" alt="TWC Placeholder" width="400" height="300">';
$data .= sprintf( '<article class="et_pb_post clearfix %s">', $twc_events_grid_class );
$data .= sprintf( '<div class="et_pb_image_container"><a href="%s">%s</a></div>', get_permalink(), $thumbnail );
$data .= sprintf( '<p class="event-meta">%s</p><hr>', tribe_events_event_schedule_details() );
$data .= sprintf( '<h2 class="entry-title"><a href="%s">%s</a></h2>', get_permalink(), get_the_title() );
$data .= sprintf( '<div class="post-content"><p>%s</p><a href="%s" class="more-link">Read More</a></div>', get_the_excerpt(), get_permalink() );
$data .= sprintf( '</article>' );
endwhile;
$data .= sprintf( '</div>' );
return $data;
wp_reset_postdata();
}
//* Add Shortcode [twc_posts tag_slug="generous-living" number="3" grid="true"]
add_shortcode( 'twc_posts', 'twc_posts_function' );
function twc_posts_function( $atts ){
// Add shortcode attributes
$a = shortcode_atts( array(
'tag_slug' => '',
'number' => 3,
'grid' => FALSE,
), $atts );
// Variables for the attributes
$twc_tag_slug = "{$a['tag_slug']}";
$twc_posts_per_page = "{$a['number']}";
$twc_posts_grid = "{$a['grid']}";
// Variables for grid (3 column) or non-grid (2 column)
if( $twc_posts_grid == TRUE ) {
$twc_posts_grid_class = 'twc_column_1_3';
$img_size = 'posts-grid';
}
if( $twc_posts_grid != TRUE ) {
$twc_posts_grid_class = 'twc_column_1_2';
$img_size = 'posts-non-grid';
}
// Query arguments
$args = array(
'post_type' => 'post',
'posts_per_page' => $twc_posts_per_page,
'tag' => $twc_tag_slug,
'order_by' => DESC,
);
// The loop
$loop = new WP_Query( $args );
$data = ''; // init
$data .= sprintf( '<div class="et_pb_blog_grid clearfix styled-posts">' );
while ( $loop->have_posts() ) : $loop->the_post();
// Get Featured Image, otherwise show placeholder
$thumbnail = get_the_post_thumbnail( $loop->ID, $img_size );
if ( empty( $thumbnail ) ) $thumbnail = '<img src="/wp-content/uploads/twc_placeholder.jpg" alt="TWC Placeholder" width="400" height="300">';
// Get Custom Author, otherwise show Author
$custom_author = get_post_meta( get_the_ID(), 'legacy_byline', true );
if( $custom_author ) {
$twc_author = sprintf('<span class="legacy-byline">%s</span>', $custom_author );
} else {
$twc_author = sprintf('<span class="author vcard">%s</span>', get_the_author_link() );
}
$data .= sprintf( '<article class="et_pb_post clearfix %s">', $twc_posts_grid_class );
$data .= sprintf( '<div class="et_pb_image_container"><a href="%s">%s</a></div>', get_permalink(), $thumbnail );
$data .= sprintf( '<h2 class="entry-title"><a href="%s">%s</a></h2>', get_permalink(), get_the_title() );
$data .= sprintf( '<p class="post-meta">%s | <span class="published">%s</span> | <span class="categories">%s</span></p>', $twc_author, get_the_time('F j, Y'), get_the_category_list( ' ', '', $loop->ID ) );
$data .= sprintf( '<div class="post-content"><p>%s</p><a href="%s" class="more-link">Read More</a></div>', get_the_excerpt(), get_permalink() );
$data .= sprintf( '</article>' );
endwhile;
$data .= sprintf( '</div>' );
return $data;
wp_reset_postdata();
}
以上是关于php 事件短代码 - 事件日历WordPress插件的主要内容,如果未能解决你的问题,请参考以下文章
php 事件日历PRO:即使对于tribe_events短代码,也使tribe_is_week()返回TRUE。
php 事件日历PRO:即使对于tribe_events短代码,也使tribe_is_week()返回TRUE。