다음 코드에 대한 단축 코드를 생성하려고합니다. 어디에서 shortcode 기능을 배치할지 모르겠습니다. 아래 코드를 시도했지만 단축 코드가 작동하지 않습니다. 기능을 추가했습니다 function lorem_function() {}
. 나는 shortcode lorem이 아래의 출력이 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