我试图利用瞬态来更快地加载我从另一个网站获取的一些数据,但数据目前没有显示出来。代码如下:
<div class="col-sm-3 news-scroller">
<div class="slick-slider pin-news-ticker">
<?php if (have_posts()) : $counter = 1; $alternate = 1; while (have_posts()) : the_post();?>
<!-- Carousel items -->
<div class="slide">
<div class="entry entry-smallest-list">
<a class="entry-thumb-wrapper" href="<?php the_permalink(); ?>">
<div class="entry-thumb">
<a href="<?php the_permalink(); ?>">
<div class="thumb-wrapper">
<?php the_post_thumbnail( \'post-small-rectangle-pin\' );?>
</div>
</a>
</div>
</a>
<div class="entry-details">
<div class="entry-date">
<small><?php echo get_the_date(\'M jS, Y\'); ?></small>
</div>
<h4 class="entry-title">
<a href="<?php the_permalink(); ?>">
<?php echo mnr_shorten_title(get_the_title()); ?>
</a>
</h4>
</div>
<div class="clearfix"></div>
</div> <!-- end .entry-small-list -->
</div><!--/ .slide-->
$trans_figures_id = \'portal_figures\';
$external_figures = get_transient( $trans_figures_id );
if ( false === $external_figures ) {
ob_start();
$production_url = \'my-url\';
$production_request = wp_remote_get( $production_url );
if(is_wp_error($production_request)) {
return false;
}
$production_body = wp_remote_retrieve_body( $production_request );
$production_data = json_decode( $production_body );
if($counter++ % 2 == 0) :
if($alternate++ % 2 == 1) : ?>
<div class="slide pin-alternate-content">
<h3>$<?php echo esc_html( number_format_i18n( $production_data[10]->Average, 1)); ?></h3>
<h4>Kurdistan Blend Price per BBL</h4>
<small>Average of last 30 shipments</small>
</div>
<?php else : ?>
<div class="slide pin-alternate-content">
<h3><?php echo esc_html( number_format_i18n( $production_data[9]->Average, 1 )); ?></h3>
<h4>Kurdistan Blend API</h4>
<small>Average of last 30 shipments</small>
</div>
<?php endif;
endif;
$external_figures = ob_get_clean();
set_transient( $trans_figures_id, $external_figures, DAY_IN_SECONDS );
}
echo $external_figures;
endwhile;
endif;
?>
</div>
</div><!-- end .col-sm-3 -->
如果没有瞬态,内容将完美显示,但加载需要很长时间。对于瞬态,内容根本不显示。如何调整此代码以使其与瞬态一起工作?