우선, 여러 외부 xml 피드 (현재 24 개의 다른 피드)에서 여러 제품으로 된 피드 페이지 당 1 개의 제품이있는 FrontPage가 있습니다. 또 다른 예는 내가 제시여러 xmlfeeds에서 php로 속성 값을 기반으로 XML 요소 가져 오기
<products>
<product>
<productID>1344</productID>
<name>Displex screen</name>
<price currency="EUR">6.95</price>
<productURL>http://www.voorbeeld.nl</productURL>
<imageURL>http://www.voorbeeld.nl/images/1543.jpg</imageURL>
<description><![CDATA[Touchscreen voor je smartphone?]]></description>
<categories>
</categories>
<additional>
<field name="price_from">14.95</field>
<field name="price_shipping">Gratis!</field>
<field name="soldout">0</field>
<field name="startdate">2012-02-07 12:00:00</field>
<field name="enddate">2012-02-08 12:00:00</field>
</additional>
</product>
</products>
서로 다른 피드 (제품)을 공급
이하나의 예
<products>
<product>
<productID>4943</productID>
<name>Inbouwspot</name>
<price currency="EUR">199.00</price>
<productURL>http://www.example.com</productURL>
<imageURL>http://static.example.com/45928-1.jpg</imageURL>
<description><![CDATA[Incl. BTW!! Verkrijgbaar in een voordeelset.]]></description>
<categories>
<category path="Aanbiedingen">Aanbiedingen</category>
<category path="Projectverlichting">Projectverlichting</category>
</categories>
<additional>
<field name="fromPrice">395.00</field>
<field name="discount">196.00</field>
<field name="deliveryCosts"></field>
<field name="deliveryTime">3-5 dagen</field>
</additional>
</product>
를 공급 : 일부 속성은 예를 들어, 같은 일에 대해 다른 이름을 가지고 다음과 같은 루프 내에서 :
<?php
// get xml file contents
$xmlurl = get_post_meta(get_the_ID(), 'plus_xmlfeed', true);
if (!empty($xmlurl)){
$xml = simplexml_load_file($xmlurl);
}
$xml->product->name = substr($xml->product->name, 0, 30).'...';
$desc = substr($xml->product->name, 0, 50).'';
?>
<li class="span3">
<div class="thumbnail">
<a href="<?php echo $xml->product->productURL ;?>">
<center><img src="<?php echo get_template_directory_uri(); ?>/img/logos/<?php echo get_post_meta(get_the_ID(), 'plus_logos', true); ?>.gif"/></center>
<center><img class="mainimg" alt="" src="<?php echo $xml->product->imageURL ;?>"/></center>
</a>
<div class="caption">
<h5><a href="<?php echo $xml->product->productURL ;?>"><?php echo $xml->product->name; ?></a></h5>
<div class="maindesc half clearfix"><div class="prijs">€ <?php echo $xml->product->price ;?></div><strike style="color: rgb(248, 148, 6);">
<?php
foreach ($xml->product->additional->field as $field) {
switch((string) $field['name']) {
case 'price_advice':
echo '€ ' .$field. '';
break;
case 'fromPrice':
echo '€ ' .$field. '';
break;
case 'oldPrice':
echo '€ ' .$field. '';
break;
case 'from_price':
echo '€ ' .$field. '';
break;
case 'adviesprijs':
echo '€ ' .$field. '';
break;
case 'advice_price':
echo '€ ' .$field. '';
break;
case 'Fromprice':
echo '€ ' .$field. '';
break;
case 'recommendedPrice':
echo '€ ' .$field. '';
break;
}
}
?>
</strike>
<p style="color: rgb(153, 153, 153);"><?php echo $desc; ?></p></div>
<div class="btn-group bot"><div class="pull-right"> </div><a class="btn btn-primary" href="<?php echo $xml->product->productURL ;?>">Kopen</a> <a class="btn" href="#<?php echo 'modal_'.get_the_ID();?>">Info</a></div>
</div>
</div>
</li>
<?php /*end loop*/ ?>
나는 wordpress를 사용하여 게시물에 피드를 입력하고이를 변수 ($ xmlurl)로 표시합니다. 특정 특성 (fromPrice 또는 from_price 등)을 포스트에 입력하고 싶으므로 피드에 적합한 것을 찾기 위해 모든 옵션을 반복 할 필요가 없습니다.
위의 내용이 훨씬 더 빠르고 효율적일 수 있음을 알고 있습니다. 누군가가 도와 줄 수 있기를 바랍니다. 나는 xpath에 관해 뭔가 읽었고, 나는 그것을 시도했지만 succes없이.