I'm using the below function to bring in the image, title, link, pubDate, and description of a blog entry to use in a SilverStripe template.
Each blog entry has multiple categories but it ALWAYS has at least 1 of the following 2 categories: "THINK Blog", "THINK Magazine" so for example it'll always be [THINK Blog, category 2, category 3, etc.] or [THINK Magazine, category 2, category 3, etc.].
I need to know if the blog entry has either the THINK Blog or the THINK Magazine category and depending on which value it has add a class to the template using a $category variable so I can style it a specific way. Any help would be great.
function getFirstPost($category = '') {
$doc = new DOMDocument();
$doc->load('http://' . $_SERVER['SERVER_NAME'] . '/feed/');
$node = $doc->getElementsByTagName('item')->item(0);
$content = $node->getElementsByTagNameNS('http://purl.org/rss/1.0/modules/content/','encoded')->item(0)->nodeValue;
$image = '';
$matches;
preg_match('/<img[^>]+>/i',$content,$matches);
if($matches) {
$image = $matches[0];
}
$itemRSS = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
//'pubDate' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
'pubDate' => date("m / d / Y",strtotime($node->getElementsByTagName('pubDate')->item(0)->nodeValue)),
'description' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'image' => $image
);
return new ArrayData($itemRSS);
}