1
我想爲下面的代碼生成簡碼。我不確定在哪裏放置短代碼功能。我嘗試了下面的代碼,但短代碼不起作用。 我已添加功能function lorem_function() {}
。我想短代碼工作,以便下面的輸出可以顯示在wordpress頁面的任何地方。爲php和html代碼生成簡碼
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
.offer-title{
font-size: 20px;
font-weight: bold;
}
.offer-col{
height: 600px;
}
.offer-row{
margin: 30px 0;
}
.offer-info{
font-size: 15px;
}
</style>
<?php
/*
Template Name: Blank - No Header, no Footer
*/
if (!defined('ABSPATH')){ die(); }
/*
* A blank Template that allows you to build landing pages, coming soon pages etc
*/
global $avia_config;
get_header();
?>
<?php
function lorem_function() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.bstcm.no/customer/-8/offers");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
$username = 'atrium',
$password = '3HnzkG2p',
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password)
));
$response = curl_exec($ch);
curl_close($ch);
$details = json_decode($response, TRUE);
/*echo"<pre>";
print_r($details);
echo"</pre>";*/
$max_count = count($details[collections]);
?>
<div class='container_wrap container_wrap_first main_color
<?php avia_layout_class('main'); ?>'>
<div class='container'>
<div class='offer-row col-sm-12'>
<?php
$flag=0;
for($i=0;$i<$max_count;$i++)
{
$count[$i] = count($details[collections][$i][offers])."....";
for($j=0;$j<$count[$i];$j++)
{
$flag++;
if($flag%2==0)
{
if($flag%4==0)
{
?>
<div class='offer-col col-sm-3'>
<img src="<?php echo $details[collections][0][offers][$j][offerFile][originalUrl]; ?>"><br/>
<span class="offer-title">
<?php echo $details[collections][0][offers][$j][offerName];?></span><br/>
<span class="offer-info">Giltighetstid:
<?php echo $details[collections][0][offers][$j][startDatetime];?></span><br/>
<span class="offer-info">T.o.m.:
<?php echo $details[collections][0][offers][$j][endDatetime];?></span><br/>
<span class="offer-info">Begränsat antal köp per kund:
<?php echo $details[collections][0][offers][$j][limitedUse];?></span><br/>
<span class="offer-info">Antal:
<?php echo $details[collections][0][offers][$j][limitedTo];?> </span><br/><br/><br/>
</div>
<?php
}
else
{
?>
<div class='offer-col col-sm-3'>
<img src="<?php echo $details[collections][0][offers][$j][offerFile][originalUrl]; ?>"><br/>
<span class="offer-title">
<?php echo $details[collections][0][offers][$j][offerName];?></span><br/>
<span class="offer-info">Giltighetstid:
<?php echo $details[collections][0][offers][$j][startDatetime];?></span><br/>
<span class="offer-info">T.o.m.:
<?php echo $details[collections][0][offers][$j][endDatetime];?></span><br/>
<span class="offer-info">Begränsat antal köp per kund:
<?php echo $details[collections][0][offers][$j][limitedUse];?></span><br/>
<span class="offer-info">Antal:
<?php echo $details[collections][0][offers][$j][limitedTo];?> </span><br/><br/><br/>
</div>
<?php
}
}
else
{
if($flag%3==0)
{
?>
<div class='offer-col col-sm-3'>
<img src="<?php echo $details[collections][0][offers][$j][offerFile][originalUrl]; ?>"><br/>
<span class="offer-title">
<?php echo $details[collections][0][offers][$j][offerName];?></span><br/>
<span class="offer-info">Giltighetstid:
<?php echo $details[collections][0][offers][$j][startDatetime];?></span><br/>
<span class="offer-info">T.o.m.:
<?php echo $details[collections][0][offers][$j][endDatetime];?></span><br/>
<span class="offer-info">Begränsat antal köp per kund:
<?php echo $details[collections][0][offers][$j][limitedUse];?></span><br/>
<span class="offer-info">Antal:
<?php echo $details[collections][0][offers][$j][limitedTo];?> </span><br/><br/><br/>
</div>
<?php
}
else
{
?>
<div class='offer-col col-sm-3'>
<img src="<?php echo $details[collections][0][offers][$j][offerFile][originalUrl]; ?>"><br/>
<span class="offer-title">
<?php echo $details[collections][0][offers][$j][offerName];?></span><br/>
<span class="offer-info">Giltighetstid:
<?php echo $details[collections][0][offers][$j][startDatetime];?></span><br/>
<span class="offer-info">T.o.m.:
<?php echo $details[collections][0][offers][$j][endDatetime];?></span><br/>
<span class="offer-info">Begränsat antal köp per kund:
<?php echo $details[collections][0][offers][$j][limitedUse];?></span><br/>
<span class="offer-info">Antal:
<?php echo $details[collections][0][offers][$j][limitedTo];?> </span><br/><br/><br/>
</div>
<?php
}
}
}
}
return $details;
?>
</div>
</div>
<?php get_footer();
}
add_shortcode('lorem', 'lorem_function');
?>
我的代碼包含html和php代碼。我如何創建一個變量來保存html div – Rashmi