Domanda

I have this feed item via SimplePie:

        <item>
            <guid isPermaLink="false">tncms-asset-7f55e8da-c801-11e2-9a4d-001a4bcf887a</guid>
            <title>Parts of old span may be used in bridge repair</title>
            <author>Author Person</author>                    
            <link>http://www.mysite.com/a.html</link>
            <description><![CDATA[Description Here.]]></description>
            <pubDate>Tue, 28 May 2013 18:45:00 -0700</pubDate>

            <enclosure url="http://mysite.com/happyLilPic.jpg" length="512" type="image/jpeg" />

        </item>

I can get everything else to show except the image with the following:

    <?php
            foreach ($feed->get_items() as $item):

    ?>

    <div class="item">
        <h3><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h3>
        <p><?php echo $item->get_description(); ?></p>

         <?php echo "<img src=\"" . $item->get_enclosure['url'][0] . "\">"; ?>
         <br><br>

    </div>

    <?php endforeach; ?>

What am I doing wrong with the enclosure???

È stato utile?

Soluzione

get_enclosure() returns a single array location containing a SimplePie_Enclosure object. The documentation shows it this way:

if ($enclosure = $item->get_enclosure())
{
   echo $enclosure->embed();
}

That uses the <embed> tag though, which is not what you want. The documentation for the Enclosure Object Lists many methods. The one I think you want is get_link(), so you would change your image tag code like this:

if ($enclosure = $item->get_enclosure())
{
   echo "<img src=\"" . $enclosure->get_link() . "\">";
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top