我目前正在努力研究如何让我的代码与Wordpress一起使用。我有它导入一个XML文件,它完全没有问题,所有内容都被加载,每个条目的各个页面在打开时完全加载。
然而,当分页生效时,它只会为所有内容加载页面1。例如。如果我点击第3页,它只会说http://website.co.uk/sales/3/并且只会加载第1页内容
我已经附上了以下代码,我假设它出现了循环错误,我已经尝试了所有内容,而且我似乎无法找到任何关于它的文档在页面模板中处理xml
<?php
$startPage = $_GET['page'];
$perPage = 11;
$currentRecord = 0;
$xml = new SimpleXMLElement('properties.xml', 0, true);
/* If Property */
if(isset($_GET['property'])) {
$propertydetailsref = $_GET['property'];
$authors = $xml->xpath('abc/abc/abc/property[@reference="'.$propertydetailsref.'"]');
/* Tabbed Section */
echo '<div id="tabNavigationContainer">
<div id="tabNavigationContent">
<span class="tabNavDescription tabCurrentSelection">Description</span>
<span class="tabNavPhotos">Photos</span>
<span class="tabNavLocation">Location</span>
<span class="tabNavViewing">Viewing</span>
<span class="tabNavFloorplans">Floorplans</span>
<span class="tabNavStreetview">Streetview</span>
<span class="tabNavPrintme">Print Me</span>
<a href="index.php"><span class="tabNavBack">Back</span></a>
</div>
</div>';
/* Content for Tabs */
echo '<div id="tabBodyContainer">';
/* DESCRIPTION */
echo '<div id="tabBodyContent" class="descriptionTabBod">';
echo '<h2>' . $authors[0]->advert_heading . '</h2>';
/* Price */
$propertypricesolo = $authors[0]->numeric_price;
$propertypricesolo = str_replace(".0000", "", $propertypricesolo);
$propertypricesolo = number_format($propertypricesolo);
echo '<div class="propertyPrice">£'.$propertypricesolo.'</div>';
/* Description */
$linebroken = $authors[0]->main_advert;
echo nl2br($linebroken);
echo '</div>';
/* PHOTOS */
echo '<div id="tabBodyContentExpanded" class="photosTabBod">';
$itwo = 0;
foreach ($authors[0]->pictures->picture as $picture) {
$pictureUrl = $picture->filename;
echo '<div id="imageFrame">';
echo '<img src="'.$pictureUrl.'" class="propertyImageInner">';
echo '</div>';
if (++$itwo == 0) break;
}
echo '</div>';
echo '<div id="showDetailsContainer">
<div id="showDetailsContent">
Show Property Details
</div>
</div>';
/* LOCATION */
echo '<div id="tabBodyContent" class="locationTabBod">';
/* Map Data */
echo '<iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0"width="100%" height="500px" src="https://maps.google.com/maps?hl=en&q='.$authors[0]->street.','.$authors[0]->postcode.','.$authors[0]->country.'&ie=UTF8&t=roadmap&z=12&iwloc=B&output=embed"></iframe>';
echo '</div>';
/* VIEWING */
echo '<div id="tabBodyContent" class="viewingTabBod">';
echo '<h2>Request a viewing or enquire</h2>';
echo '<b>Content here</b>';
/* Contact Form */
echo '</div>';
/* FLOOR PLANS */
echo '<div id="tabBodyContent" class="floorplansTabBod">';
echo '<h2>Click floor plan to enlarge</h2>';
$ithree = 0;
foreach ($authors[0]->floorplans->floorplan as $fplan) {
$fplanurl = $fplan->filename;
echo '<img src="'.$fplanurl.'" class="floorplanImage">';
if (++$ithree == 0) break;
}
echo '</div>';
/* STREET VIEW */
echo '<div id="tabBodyContent" class="streetTabBod">';
echo '<iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0"width="100%" height="500px" src="https://maps.google.com/maps?hl=en&q='.$authors[0]->street.','.$authors[0]->postcode.','.$authors[0]->country.'&ie=UTF8&t=roadmap&z=12&iwloc=B&output=embed"></iframe>';
echo '</div>';
echo '</div>';
/* If Archive */
} else {
echo '<div id="propertyArchiveContainer"><div id="propertyArchiveContent">';
foreach($xml->branches->branch->properties->property as $property){
$currentRecord += 1;
if($currentRecord > ($startPage * $perPage) && $currentRecord < ($startPage * $perPage + $perPage)){
echo '<div id="property">';
echo '<a href="index.php?property='.$property["reference"].'" class="'.$property["reference"].'">';
echo '<h2 style="margin-bottom:5px;padding-bottom:5px;border-bottom:1px solid #ddd;">' . $property->advert_heading . '</h2>';
echo '</a>';
$propertyprice = $property->numeric_price;
$propertyprice = str_replace(".0000", "", $propertyprice);
$propertyprice = number_format($propertyprice);
echo '£'.$propertyprice.'<br>';
/* Pictures */
$itwo = 0;
foreach ($property->pictures->picture as $picture) {
$pictureUrl = $picture->filename;
echo '<img src="'.$pictureUrl.'" class="propertyImage">';
if (++$itwo == 1) break;
}
echo '</div>';
}
}
/* Pagination */
echo '<div id="pagination">';
echo "<a href='index.php'>1</a>";
for ($i = 1; $i <= ($currentRecord / $perPage); $i++) {
echo "<a href='../sales?page=".$i."'>".($i+1)."</a>";
}
echo '</div>';
echo '</div></div>';
}
/* End of Archive */
?>
任何帮助都将永远受到赞赏
答案 0 :(得分:0)
发现Wordpress已经设置了页面查询,这就是为什么它会发生冲突,设法将其更改为Section并且作业很好。
希望有一天能帮助别人