SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't get wordpress feed to display full article...

    This is probably going to be a really simple fix... I just can't figure it out.

    I want to display the posts from a wordpress category on the following page: http://www.oe-design.com/about-press.php?test

    I've managed to do so but when I show the 'description' on the page (my code: $item->description), it only shows a snippet of the article, not the full article...

    What do I need to use to show the full article?

    I am trying to view the wordpress RSS feed but when I view it in FireFox it asks me to subscribe so I can't actually view it and see what I need to do to view the full article. Safari shows their own custom feed layout...

    Hopefully I am making sense

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If that's what you get out of $item->description, that's probably all that's in the feed. Lots of sites only publish excerpts in the RSS feeds, not the full post content.

    To be sure, you should look at the raw feed. An easy way to do that if you're having trouble viewing it in your browser would be to put a link to the feed on a webpage, then right click the link and "save as" a file on your computer. Then you can open it in notepad.

  3. #3
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aha thank you Dan! Save target as! So simple!

    OK, so I downloaded the feed and found what I needed however it's called 'content:encoded'... here is a sample of the rss feed...

    Code:
    <item>
        <!-- more rss here.... -->
    
        <description><![CDATA[this is the description]]></description>    
        <content:encoded><![CDATA[<p>this is the full article</p>]]></content:encoded>
        
        <!-- more rss here.... -->            
    </item>
    I tried this: $item->content:encoded but PHP doesn't like it...


    Parse error: syntax error, unexpected ':', expecting ',' or ';' in /home/.../public_html/about-press.php on line 25

    Any ideas on how I can read that field?

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Try $item->content (without the :encoded).

    Just a guess though, as I have no idea what code you're using to parse the RSS, and therefore no idea what kind of object $item is an instance of and what its interface is.

  5. #5
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha that would probably help if I sent the code. See below... Oh and BTW, $item->content doesn't work...

    PHP Code:
    $curl curl_init();
        
    curl_setopt($curlCURLOPT_URL'http://www.oe-design.com/blog/category/press-releases/feed/');
        
    curl_setopt($curlCURLOPT_RETURNTRANSFER1);
        
    curl_setopt($curlCURLOPT_CONNECTTIMEOUT0);
        
    $xml curl_exec($curl);
        
    curl_close($curl);
        
    $xmlObj simplexml_load_string$xml );
        
    $x 0;
        foreach ( 
    $xmlObj->channel->item as $item ) {
            if ( 
    $x == 10 )
                break;
            echo 
    '<h2>' $item->title '</h2>' $item->description;
            
    $x++;
        } 

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This tutorial has an example of accessing the content item, perhaps it will be useful:

    http://blog.stuartherbert.com/php/20...rse-rss-feeds/

    I don't use SimpleXML to parse RSS myself.

    http://simplepie.org/

  7. #7
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using simplepie now and it worked! woohoo! I'm not sure how much you know about it but now I'm getting this error:

    Warning: ./cache/9a6ae70bf3b771719797b68ad270b242.spc is not writeable in /home/.../public_html/includes/simplepie.inc on line 1779

    My code

    PHP Code:
    include_once 'includes/simplepie.inc'
        
    $feed = new SimplePie('http://www.oe-design.com/blog/category/press-releases/feed/');
        
    $feed->enable_cache(false);
        foreach (
    $feed->get_items(05) as $item):
            echo 
    '<h2>' $item->get_title() . '</h2>' $item->get_content();
        endforeach; 

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    SimplePie caches feeds so that they don't have to be fetched every time the page is loaded by another visitor. For that to work, it needs a cache directory that is writeable by the user PHP runs as. You'll want to change the permissions so it can do so, or turn off caching.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •