Suin\RSSWriter\Item::category PHP Method

category() public method

public category ( $name, $domain = null )
    public function category($name, $domain = null)
    {
        $this->categories[] = [$name, $domain];
        return $this;
    }

Usage Example

Example #1
0
function generate_rss($posts)
{
    $feed = new Feed();
    $channel = new Channel();
    $rssLength = config('rss.char');
    $channel->title(blog_title())->description(blog_description())->url(site_url())->appendTo($feed);
    foreach ($posts as $p) {
        if (!empty($rssLength)) {
            if (strlen(strip_tags($p->body)) < config('rss.char')) {
                $string = preg_replace('/\\s\\s+/', ' ', strip_tags($p->body));
                $body = $string . '...';
            } else {
                $string = preg_replace('/\\s\\s+/', ' ', strip_tags($p->body));
                $string = substr($string, 0, config('rss.char'));
                $string = substr($string, 0, strrpos($string, ' '));
                $body = $string . '...';
            }
        } else {
            $body = $p->body;
        }
        $item = new Item();
        $cats = explode(',', str_replace(' ', '', strip_tags(remove_accent($p->category))));
        foreach ($cats as $cat) {
            $item->category($cat, site_url() . 'category/' . strtolower($cat));
        }
        $item->title($p->title)->pubDate($p->date)->description($body)->url($p->url)->appendTo($channel);
    }
    echo $feed;
}
All Usage Examples Of Suin\RSSWriter\Item::category