Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

WordPress If In Category - RSS Feed


Reply


3 Posts   599 Views

Avatar
VictorH

Community Member, 29 Posts

27 April 2012 at 8:15am

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);
}

Avatar
DesignerX.com.au

Community Member, 107 Posts

29 April 2012 at 6:31pm

can i have a look at post.php & PostsHolder.php . The files you use for the "blog"

Avatar
VictorH

Community Member, 29 Posts

29 April 2012 at 10:26pm

The blog is a WordPress installation. Does that help? I forgot to mention that.