【问题标题】:Custom XML Pagination in WordpressWordpress 中的自定义 XML 分页
【发布时间】:2015-10-09 00:08:17
【问题描述】:

我目前正在尝试研究如何使我的代码与 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 */

?>

任何帮助将永远感激不尽

【问题讨论】:

    标签: php xml wordpress pagination


    【解决方案1】:

    发现 Wordpress 已经为 Page 查询设置了这就是它发生冲突的原因,设法将其更改为 Section 并且这项工作做得很好。

    希望有一天这对其他人有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-20
      • 2012-06-21
      • 2017-02-22
      • 2017-03-19
      • 2016-04-18
      • 2016-11-05
      相关资源
      最近更新 更多