【发布时间】:2017-06-20 23:16:22
【问题描述】:
我正在使用高级自定义字段在 Wordpress 中构建时间线页面。我有一个活动开始日期和结束日期,我需要根据活动的持续时间调整 div 的高度。
我到目前为止的代码如下。 <div class="span"></div> 是需要高度的 div。我需要的高度比的估计值约为每 30.5 天 100 像素。开始/结束日期的字段名称为timeline_datespan_start 和timeline_datespan_end,字段类型为日期选择器。
<?php
$custom_args = array(
'post_type' => 'timeline',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_key' => 'timeline_date',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
$custom_query = new WP_Query( $custom_args ); ?>
<?php if ( $custom_query->have_posts() ) : ?>
<!-- the loop -->
<?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<!-- event span -->
<?php
$timeline_span = get_field('timeline_datespan_start');
if( !empty($timeline_span) ): ?>
<div class="event <?php the_field('timeline_datespan_start'); ?>">
<div class="timeline-event-span">
<div class="span"></div><div class="line"></div>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <span class="timeline-date">(<?php the_field('timeline_datespan_start'); ?> - <?php the_field('timeline_datespan_end'); ?>)</span>
</div>
</div>
<?php endif; ?>
<!-- /event span -->
<?php // endif; ?>
<?php endwhile; ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
【问题讨论】:
标签: javascript php wordpress height advanced-custom-fields