循环中的Echo HTML输出不正常

时间:2018-02-17 12:38:48

标签: php html

有一些格式问题 - 让PHP工作,只是让我有点疯狂的HTML!

我基本上是通过API提取一些内容并希望将其呈现在网格中。有多个列表。

当我格式化我认为应该起作用的内容时,每个项目都会堆叠在前一个项目下面并且格式不正确。

我确信这是一个简单的解决办法,但我已经盯着这几天了,我无法弄清楚出了什么问题 - 所以对你而言!

以下是出现错误的HTML代码:

<article id="'.$name.'" class="'.$name.' project type-project status-publish format-standard has-post-thumbnail hentry pj-categs-adult-cats pj-categs-cats pj-categs-male isotope-item shortcode_animated" data-category="adult-cats cats male" style="width: 400px; position: absolute; left: 0px; top: 0px; transform: translate3d(0px, 0px, 0px);">

<div class="project_outer">
    <figure class="cmsms_img_rollover_wrap preloader">
        <img width="580" height="460" src="'.$medium_photo.'" class="full-width wp-post-image" alt="'.$name.'" title="'.$name.'">
<div class="cmsms_img_rollover">
    <span class="cmsms_img_rollover_divider"></span>
        <a href="'.$medium_photo.'" rel="ilightbox" title="'.$name.'" class="cmsms_image_link"><span class="cmsms_theme_icon_search"></span></a><a href="http://test.xxxx.org.au/Project/'.$name.'/" title="'.$name.'" class="cmsms_open_link"><span class="cmsms_theme_icon_rollover_open_link"></span></a>
</div>
</figure>
<div class="project_inner">
    <header class="cmsms_project_header entry-header">
    <h6 class="cmsms_project_title entry-title"><a href="http://test.haart.org.au/davetest/?id='.$animal_id.'">'.$name.'</a></h6>
    </header>
<footer class="cmsms_project_footer entry-meta">
    </a>
    </footer>
</div>
<div class="cl"></div>
</div>
</article>

基本上,我希望每个人都能自己显示,然后当没有更多列表时,关闭HTML。

如果你不知道我在说什么,请打我!

编辑完整代码 - 在下面稍作修改:

<?php 

// Start PHP/API Code
//----------------------------------------
// Open CuRL/JSON Stuff

$ch = curl_init();
$pr_id=$_GET['pr_id'];
$url="https://www.xxxxxx.com.au/api/listings?token=1234&group_id=1234&species=Dog&page=$pg";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Accept: application/json',
    'X-some-API-Key: 1234',
));
$json = json_decode(curl_exec($ch), true);

// Functions relating to the Echo Code
$prpage=($json['page']);
$prperpage=($json['per_page']);
$prtotalpage=($json['total_pages']);
echo '<div class="portfolio grid large_gap perfect cmsms_3 isotope" style="position: relative; overflow: hidden; height: 1356px;">
    <h6>Page '.$pg.' of '.$prtotalpage.'</h6>';
foreach($json['listings'] as $listing)
{
    $short_personality=substr($listing['personality'],0,500);
    $peturl="http://www.xxxx.org.au/pet-info/?petid=".$listing['id'];
    $photos=$listing['photos'];
    $medium_photo=$listing['photos'][0]['xlarge_900'];
    $gallery_first=$listing['photos'][0]['large_340'];
    $gender_class=strtolower($listing['gender']);
    $breed_class=strtolower($listing['species']);
    $name=($listing['name']);
    $date=$listing['created_at'];
    $date_updated=$listing['last_updated'];
    $unique_gallery_name="ilightbox['.$inc.']";
    $inc++;
    foreach($listing['photos'] as $photosthumb)
    {
        $photo_thumb_large=$photosthumb["medium_130"];
        $photo_thumb_hidden=$photosthumb["small_80"];
    }

    // General IF/AND/ELSE Statements to refine the Echo Output
    if($listing['photos'] == null) {
        $medium_photo="http://www.xxxx.org.au/wp-content/themes/xxxx/images/photo_coming_soon.png";
    }
    if($listing['desexed'] == "true") {
        $desexed="Yes";
    }
    else {
        $desexed="No";
    }
    if($listing['foster_needed'] == "true") {
        $foster_needed="Yes";
    }
    else {
        $foster_needed="No";
    }
    if($listing['vaccinated'] == "Yes") {
        $vaccinated="yes";
    }
    else {
        $vaccinated="no";
    }
    if($listing['wormed'] == "Yes") {
        $wormed="yes";
    }
    elseif($listing['wormed'] == "No") {
        $wormed="no";
    }
    else {
        $wormed="no";
    }
    if($listing['heart_worm_treated'] == "true") {
        $heart_worm_tested="Yes";
    }
    elseif($listing['heart_worm_treated'] == "Unsure") {
        $heart_worm_tested="Unsure";
    }
    else {
        $heart_worm_tested="No";
    }
    if($listing['species'] == "Dog") {
        $adoption_enquiry_link="http://www.xxxx.org.au/pre-adoption-form-dogs/?dog_name=$name";
        $hwt="list-$heart_worm_tested";
    }
    elseif($listing['species'] == "Cat") {
        $adoption_enquiry_link="http://www.xxxx.org.au/pre-adoption-form-cats/?cat_name=$name";
        $hwt="list-hwt-hidden";
    }

    $animal_id=($listing['id']);

    $adoption_poster_link="http://www.xxxx.org.au/poster.php?animal_id=$animal_id";

    // Echo the output
    echo '<article id="'.$name.'" class="'.$name.' project type-project status-publish format-standard has-post-thumbnail hentry pj-categs-adult-cats pj-categs-cats pj-categs-male isotope-item shortcode_animated" data-category="adult-cats cats male" style="width: 400px; position: absolute; left: 0px; top: 0px; transform: translate3d(0px, 0px, 0px);">
           <div class="project_outer">
               <figure class="cmsms_img_rollover_wrap preloader">
                   <img width="580" height="460" src="'.$medium_photo.'" class="full-width wp-post-image" alt="'.$name.'" title="'.$name.'">
                   <div class="cmsms_img_rollover">
                       <span class="cmsms_img_rollover_divider"></span>
                       <a href="'.$medium_photo.'" rel="ilightbox" title="'.$name.'" class="cmsms_image_link"><span class="cmsms_theme_icon_search"></span></a><a href="http://test.xxxx.org.au/Project/'.$name.'/" title="'.$name.'" class="cmsms_open_link"><span class="cmsms_theme_icon_rollover_open_link"></span></a>
                   </div>
               </figure>
               <div class="project_inner">
                    <header class="cmsms_project_header entry-header">
                        <h6 class="cmsms_project_title entry-title">        <a href="http://test.xxxx.org.au/davetest/?id='.$animal_id.'">'.$name.'</a></h6>
                    </header>
                    <footer class="cmsms_project_footer entry-meta">
                        </a>
                    </footer>
                </div>
                <div class="cl"></div>
            </div>
        </article>';
    // Close the CURL
}
echo '<div align="center" class="ac-pages-wrapper">';
    if ($prpage > 1)
        echo '<a href="?pg='.($prpage - 1).'" class="first" title="Back"><</a>';
    for ($i = 1; $i <= $prtotalpage; $i++)
    {
        if ($i == $prpage)
            echo '<a href="?pg='.$i.'" class="current">'.$i.'</a>';
        else
            echo '<a href="?pg='.$i.'" class="page">'.$i.'</a>';
    }
    if ($prpage < $prtotalpage)
        echo '<a href="?pg='.($prpage + 1).'" class="last" title="Next">></a>';
echo '</div>';
curl_close($ch);

0 个答案:

没有答案