Jump to content

RSS Enhanced with image tags


melissa_boyle
 Share

Recommended Posts

Hi Guys,

I have recently joined bloglovin and have implemented the RSS enhanced module onto my blog, encolsures for images are working ok but I was wondering if I can implement these to be wrapped in an image tag to allow blog lovin to be able to carry imagery through.

Any help would be greatly appreciated.

Thanks,

Mel

Link to comment
Share on other sites

you should probably post this on the module topic itself (in the future, e.g. don't double post this).

https://processwire.com/talk/topic/6540-markup-rss-enhanced/

you can either roll your own custom RSS feed, or you'll need to append an image tag to the description so that it is within the [[CDATA]]

you'd need to add this around line 149

$description .= $this->renderImage($page);

you'd need to add something like this to the module (untested)

    /**
     * add an image to the description
     * 
     *
     */
    protected function renderImage(Page $page) {

        $name = $this->itemEnclosureField;
        if(!$page->template->hasField($name)) return '';
        $fieldObject = $this->fields->get($name); // field object
        $field = $page->$name;
        $fieldType = $fieldObject->type;
        $maxFiles = $fieldObject->maxFiles;

        if(count($field) === 0) {
            return '';
        } else if ($maxFiles != 1) {
            $field = $field->first();
        }

        if($field instanceof Pageimage) {

            $width = (int) $this->width;
            $height = (int) $this->height;

            if ($width && $height && $this->boundingbox) {
                $ratiox = $width / $field->width;
                $ratioy = $height / $field->height;

                $width = min($ratiox, $ratioy) * $field->width;
                $height = min($ratiox, $ratioy) * $field->height;

                $field = $field->size($width, $height);
            } else if($width || $height) {
                $field = $field->size($width, $height);
            }

            return "<img src='{$field->httpUrl}' />";
            
        } else {
        	return '';
        }

        
    }
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...