Я создал с помощью метабокса. Я хочу показывать ближайшее последнее предстоящее сообщение, только если дата публикации закрыта, другое ближайшее сообщение должно показывать это место. Мой код показывает все предстоящие сообщения.
function timer2_shortcode( $atts , $content = null ) {
$atts = shortcode_atts(
array(
'category' => '',
),
$atts
);
$args = array(
'post_type' => 'post',
'category_name' => $atts['category'],
'posts_per_page' => -1,
'meta_key' => 'event_start_date',
'orderby' => 'meta_value',
'order' => 'DSC'
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
if (has_post_thumbnail( $post->ID ) ) {
$url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
}
else {
$image = get_bloginfo('template_directory') . '/assets/images/default.png';
}
$start_date = get_post_meta(get_the_ID(), 'event_start_date', true);
$end_date = get_post_meta(get_the_ID(), 'event_end_date', true);
$start_time = strtotime($start_date);
$start = date('Y-m-d',$start_time);
$end_time = strtotime($end_date);
$end = date('Y-m-d',$end_time);
$start_day = date('d',$start_time);
$end_day = date('d',$end_time);
$start_year = date('Y',$start_time);
$end_year = date('Y',$end_time);
$start_month = date('M',$start_time);
$end_month = date('M',$end_time);
if ($start == $end) {
$duration = $start_month. ' ' . $start_day.', '.$start_year;
} else {
$duration = $start_month. ' ' . $start_day.' - ' . $end_month.' '.$end_day.', '.$start_year;
}
$current_date = date('Y-m-d');
if ($start == $end) {
$duration = $start_month. ' ' . $start_day.', '.$start_year;
} else {
$duration = $start_month. ' ' . $start_day.' - ' . $end_month.' '.$end_day.', '.$start_year;
}
$current_date = date('Y-m-d');
if (($start < $current_date && $end < $current_date) || (!$start_date) || (!$end_date) ) {
if (has_post_thumbnail( $post->ID ) ) {
$url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
$imagesopen='';
$imagesclose='';
} else {
$image = get_bloginfo('template_directory') . '/assets/images/default.png';
$images='';
}
$outercat.='';
$outercat.='';
$outercat.=$imagesopen;
$outercat.='';
$outercat.='';
$outercat.=''.get_the_title().'';
$outercat.='';
$outercat.='';
$outercat.=$imagesclose;
$outercat.='';
$outercat.='';
}
if ( $end >= $current_date ) {
$headcat.='
var countDownDate = new Date("'.countdown__get_meta( 'countdown__countdown_month' ) .countdown__get_meta( 'countdown__countdown_date' ).', '.countdown__get_meta( 'countdown__countdown_year' ).' 15:37:25").getTime();
';
$headcat.='';
$headcat.='';
$headcat.='';
$headcat.='';
$headcat.='';
$headcat.=''.get_the_title().'';
$headcat .= '
' . limit_words(get_the_excerpt(), '20') . '
';
$headcat.=''.activity_meta_get_meta( 'activity_meta_location' ).'';
$headcat.=''.activity_meta_get_meta( 'activity_meta_time_' ).'';
$headcat.='
';
$headcat.='';
$headcat.='';
$headcat.='';
$headcat.='';
$headcat.='';
}
wp_reset_postdata();
}
}
$out.='';
$out.='';
$out.='';
$out.='';
$out.='';
$out.=$outercat;
$out.='';
$out.='';
$out.=$headcat;
$out.='';
$out.='';
return $out;
}
add_shortcode( 'timer2', 'timer2_shortcode' );
Подробнее здесь: https://stackoverflow.com/questions/527 ... want-to-sh
Я создал код для прошлых и предстоящих событий, используя мета-поле. Я хочу показать ближайшие последние предстоящие пуб ⇐ Php
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение