Jump to:

23493 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » WordPress If In Category - RSS Feed

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

Page: 1
Go to End
Author Topic: 567 Views
  • VictorH
    Avatar
    Community Member
    29 Posts

    WordPress If In Category - RSS Feed Link to this post

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

  • DesignerX.com.au
    Avatar
    Community Member
    107 Posts

    Re: WordPress If In Category - RSS Feed Link to this post

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

  • VictorH
    Avatar
    Community Member
    29 Posts

    Re: WordPress If In Category - RSS Feed Link to this post

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

    567 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.