1. Politist
  2. Monday, 16 January 2017
Hi! I have a website and I'm using the resource provided by Politist, which is the blog.
To show the image we use "Helix Blog Options", where you can set a Featured Image.
So when I do post an article setting and image in it I want to automatically create the tag with og:image from facebook with this image aswell.

To make myself more clear.
1 - I created an article;
2 - Set an image into Helix Blog Options > Featured Image
3 - I want to automatically create < meta property="og:type" content=".....jpg" > from the image set up into Helix Blog Options > Featured image.

The website I'm using is http://www.cristianoalmeidabp.com.br and you can see that I already have all the meta tags, but can't figure out how to get the image automatically.
See here: http://www.cristianoalmeidabp.com.br/atuacao/ultimas-noticias/97-dando-voz-aos-distritos-fala-dorandia

I Hope you guys can help me out.
Thanks in advance.
Responses (11)
Hi,
I have to check if in current version of template I can do something, if not, I will give you tip or ask to wait for template update.
  1. more than a month ago
  2. Politist
  3. # 1
Ok, last questions ::
1) Are you using any sort of plugin for Open Graph ?
2) Have you edited that file: templates\shaper_politcs\html\com_content\article\default.php
-----

Open Graph tags can added to that template, because right now they are not included.
In means that you can disable Open Graph plugin if you have any.
And paste following code:


//get image
$article_attribs = json_decode($this->item->attribs);
$article_images = json_decode($this->item->images);
$article_image = '';
if(isset($article_attribs->spfeatured_image) && $article_attribs->spfeatured_image != '') {
$article_image = $article_attribs->spfeatured_image;
} elseif(isset($article_images->image_fulltext) && !empty($article_images->image_fulltext)) {
$article_image = $article_images->image_fulltext;
}

//opengraph
$document = JFactory::getDocument();
$document->setTitle($this->item->title);
$document->addCustomTag('<meta property="og:url" content="'.JURI::current().'" />');
$document->addCustomTag('<meta property="og:type" content="article" />');
$document->setDescription( JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) );
$document->addCustomTag('<meta property="og:title" content="'. $this->item->title .'" />');
$document->addCustomTag('<meta property="og:description" content="'. JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) .'" />');
if ($article_image) {
$document->addCustomTag('<meta property="og:image" content="'. JURI::root().$article_image.'" />');
$document->addCustomTag('<meta property="og:image:width" content="600" />');
$document->addCustomTag('<meta property="og:image:height" content="315" />');
}

$post_format = $params->get('post_format', 'standard');
$has_post_format = $tpl_params->get('show_post_format');
if($this->print) $has_post_format = false;





here: templates\shaper_politcs\html\com_content\article\default.php

before closing ?>
<article


---
If you afraid to do that, just download a zip file , unzip and replace
Attachments (1)
  1. more than a month ago
  2. Politist
  3. # 2
Hi,
I have to check if in current version of template I can do something, if not, I will give you tip or ask to wait for template update.

Hi! Sending you the attachment with the versions.
I'm afraid to update it, since the site is already live, can't take any risk of breaking things, and I don't have subscription to Page Builder to download the last version and update it.
Attachments (1)
  1. more than a month ago
  2. Politist
  3. # 3
Ok, last questions ::
1) Are you using any sort of plugin for Open Graph ?
2) Have you edited that file: templates\shaper_politcs\html\com_content\article\default.php
-----

Open Graph tags can added to that template, because right now they are not included.
In means that you can disable Open Graph plugin if you have any.
And paste following code:


//get image
$article_attribs = json_decode($this->item->attribs);
$article_images = json_decode($this->item->images);
$article_image = '';
if(isset($article_attribs->spfeatured_image) && $article_attribs->spfeatured_image != '') {
$article_image = $article_attribs->spfeatured_image;
} elseif(isset($article_images->image_fulltext) && !empty($article_images->image_fulltext)) {
$article_image = $article_images->image_fulltext;
}

//opengraph
$document = JFactory::getDocument();
$document->setTitle($this->item->title);
$document->addCustomTag('<meta property="og:url" content="'.JURI::current().'" />');
$document->addCustomTag('<meta property="og:type" content="article" />');
$document->setDescription( JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) );
$document->addCustomTag('<meta property="og:title" content="'. $this->item->title .'" />');
$document->addCustomTag('<meta property="og:description" content="'. JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) .'" />');
if ($article_image) {
$document->addCustomTag('<meta property="og:image" content="'. JURI::root().$article_image.'" />');
$document->addCustomTag('<meta property="og:image:width" content="600" />');
$document->addCustomTag('<meta property="og:image:height" content="315" />');
}

$post_format = $params->get('post_format', 'standard');
$has_post_format = $tpl_params->get('show_post_format');
if($this->print) $has_post_format = false;





here: templates\shaper_politcs\html\com_content\article\default.php

before closing ?>
<article


---
If you afraid to do that, just download a zip file , unzip and replace


Hi!
1) Yes. I'm using Phoca Open Graph. Latest version.
2) No. I didn't change any file.
  1. more than a month ago
  2. Politist
  3. # 4
What do you recommend me to do?
1) Update it all, disable open graph plugin and then install the code?
2) Disable open graph plugin and install the code without any update?

I'm kind lost in here hehehe
  1. more than a month ago
  2. Politist
  3. # 5
Disable open graph plugin
then use my file (default.php) to replace old file.
That's all.
---
or if you have skills , you can customize Phoca Open Graph tool. hehehe
  1. more than a month ago
  2. Politist
  3. # 6
Disable open graph plugin
then use my file (default.php) to replace old file.
That's all.
---
or if you have skills , you can customize Phoca Open Graph tool. hehehe


I also can do that. But I would like to know which code will capture the image from Helix Blog.
If you can tell me that =P
  1. more than a month ago
  2. Politist
  3. # 7
first part of my previous code


//get image
$article_attribs = json_decode($this->item->attribs);
$article_images = json_decode($this->item->images);
$article_image = '';
if(isset($article_attribs->spfeatured_image) && $article_attribs->spfeatured_image != '') {
$article_image = $article_attribs->spfeatured_image;
} elseif(isset($article_images->image_fulltext) && !empty($article_images->image_fulltext)) {
$article_image = $article_images->image_fulltext;
}



I guess.
  1. more than a month ago
  2. Politist
  3. # 8
Disable open graph plugin
then use my file (default.php) to replace old file.
That's all.
---
or if you have skills , you can customize Phoca Open Graph tool. hehehe


Got it to work with Phoca Open Graph.
Include some code that you past here.

First I add

$article_attribs = json_decode($row->attribs);

Had to change the $this->item for $row->

Then below I add this if

if(isset($article_attribs->spfeatured_image) && $article_attribs->spfeatured_image != '') {
$pictures = $article_attribs->spfeatured_image;
$document = JFactory::getDocument();
$document->addCustomTag('<meta property="og:image" content="'. JURI::root().$pictures.'" />');
$imgSet = 1;
}


Thanks for the help!
  1. more than a month ago
  2. Politist
  3. # 9
Hy!
And this version perfect for Helix Ultimate... :

i use in default.php top...

after:

defined ('_JEXEC') or die();

use Joomla\CMS\HTML\HTMLHelper;
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers');


addedand modified this:


//get image
$article_attribs = json_decode($this->item->attribs);
$article_images = json_decode($this->item->images);
$article_image = '';
if(isset($article_attribs->helix_ultimate_image) && $article_attribs->helix_ultimate_image != '') {
$article_image = $article_attribs->helix_ultimate_image;
} elseif(isset($article_images->image_fulltext) && !empty($article_images->image_fulltext)) {
$article_image = $article_images->image_fulltext;
}

//opengraph
$document = JFactory::getDocument();
$document->setTitle($this->item->title);
$document->addCustomTag('<meta property="og:url" content="'.JURI::current().'" />');
$document->addCustomTag('<meta property="og:type" content="article" />');
$document->setDescription( JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) );
$document->addCustomTag('<meta property="og:title" content="'. $this->item->title .'" />');
$document->addCustomTag('<meta property="og:description" content="'. JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) .'" />');
if ($article_image) {
$document->addCustomTag('<meta property="og:image" content="'. JURI::root().$article_image.'" />');
$document->addCustomTag('<meta property="og:image:width" content="600" />');
$document->addCustomTag('<meta property="og:image:height" content="315" />');
}
  1. more than a month ago
  2. Politist
  3. # 10


There are no replies made for this post yet.
Be one of the first to reply to this post!


This forum is archived

This forum has been archived. Please use JoomShaper official support system.