当我将代码添加到sage(wordpress)中的functions.php时,页面将重新加载
当我使用get_transient函数时,页面将重新加载 下面的语句显示了我的代码: 我正在使用sage和下面的代码,这些代码放在像feature.blade.php这样的blade文件中当我将代码添加到sage(wordpress)中的functions.php时,页面将重新加载,wordpress,Wordpress,当我使用get_transient函数时,页面将重新加载 下面的语句显示了我的代码: 我正在使用sage和下面的代码,这些代码放在像feature.blade.php这样的blade文件中 <div class="popular-products-holder"> <?php $products = get_remote_product('home'); if( ! empty( $products['data'] ) ) :
<div class="popular-products-holder">
<?php
$products = get_remote_product('home');
if( ! empty( $products['data'] ) ) :
foreach( $products['data'] as $product) :
if($product->images[0]->src) :
?>
<div id="<?php echo $product->id; ?>" style="background-image:url();" data-srcset="<?php echo $product->images[0]->src; ?>" class="lazy-bg col-12 col-sm-6 col-md-6 col-lg-6 col-xl-3 pp">
<div class="title-select row align-items-end">
<div class="col-12 col-sm-7 align-self-center product-info">
<h4>{{ $product->name }}</h4>
</div>
<div class="col-12 col-sm-5 align-self-center">
<a id="select{{ $product->id }}" class="btn btn-black btn-block product-sel" href="/find-what-you-need-where-ever-you-are/#filter-block-start">Select</a>
</div>
</div>
</div>
<?php
endif; endforeach; endif;
?>
</div>
我怎样才能修好它?(每次使用瞬态时,我都会在瀑布中看到重新加载页面)
我检查了插件,没有任何插件,我得到了相同的结果
提前感谢。我从html中删除了style=“background image:url();”
,并将其修复
function get_remote_product($page = null){
// source url
$remote_url = 'https://woocommerce-490897.com/wp-json/wc/v3/products';
// check the transient
$body = get_transient('prospray_product_'.$page);
// fetch data from source if not exist transient
if(empty($body)){
$data = config_get_remote($page,$remote_url);
$body = wp_remote_retrieve_body( $data['result'] );
set_transient('prospray_product_'.$page,$body,86400);
}
return ['data' => json_decode($body) , 'reference_site'=>$remote_url];
}
function config_get_remote($page = null, $remote_url){
// per page
$count = 12;
// per page for home
if($page == 'home'){
$count=4;
$page=1;
}
// check language
$lang = weglot_get_current_language() == 'no' ? 'nb' : 'en';
// set paginiation
$page = $page != null ? "&page={$page}" : '' ;
// make query
$params = "?per_page={$count}&orderby=menu_order&order=asc&lang={$lang}".$page;
// set headers
$auth = array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'ck_a442a87286a6f9269e54dd47cbf:cs_8b3a4ff671e46843a88415e4214' )
)
);
// get data
$result = wp_remote_get( $remote_url.$params ,$auth);
if( is_wp_error( $result ) ) :
return FALSE;
endif;
// get total pages for next/prev links
$totalpages = wp_remote_retrieve_header($result,'x-wp-totalpages');
return [
'result'=>$result,
'totalpages'=>$totalpages
];
}