How to parse category term from Wordpress ATOM feed in PHP? -



How to parse category term from Wordpress ATOM feed in PHP? -

i have standard atom feed wordpress instance. in feed, next category items appear:

<category scheme="http://alpha-s2new.simplescienceinc.com/blog" term="blog" /> <category scheme="http://alpha-s2new.simplescienceinc.com/blog" term="mobile" /> <category scheme="http://alpha-s2new.simplescienceinc.com/blog" term="websites" />

i'm using next code parse feed:

foreach ($rss->getelementsbytagname('entry') $node) { $item = array( 'title' => $node->getelementsbytagname('title')->item(0)->nodevalue, 'desc' => $node->getelementsbytagname('content')->item(0)->nodevalue, 'link' => $node->getelementsbytagname('link')->item(0)->nodevalue, 'date' => $node->getelementsbytagname('updated')->item(0)->nodevalue, 'author' => $node->getelementsbytagname('name')->item(0)->nodevalue, 'postid' => $node->getelementsbytagname('id')->item(0)->nodevalue, 'cats' => $node->getelementsbytagname('category')->item(0)->nodevalue ); array_push($feed, $item); }

as can see.. lastly item pulls "category" node. returns empty string. , think know why. question is.. what's syntax pull terms?

term attribute, need utilize getattribute info it. example:

// $dom domdocument object holding xml $cats = $dom->getelementsbytagname('category'); foreach ($cats $c) { echo "term: " . $c->getattribute('term') . php_eol; }

output:

term: blog term: mobile term: websites

if you're using $c->nodevalue, won't because node doesn't have value--it's empty. first category's term attribute, you'll need substitute current line this:

'cats' => $node->getelementsbytagname('category')->item(0)->getattribute('term')

php wordpress feed atom

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -