× Joomla Facebook Connect support forum

Topic-icon Adding FB social graph properties to K2 items dynamically

Active Subscriptions:

None
Hi , I am using JFB 4.1.2 and I'd like to add additional facebook social graph properties for K2 items dynamically.

So, I want to add:
meta property="og:image" content=" $this->item->image"
meta property="og:description" content=" $this->item->image_caption"
(where $this->item is the K2 item).

Thanks for your help!
Stefan
The topic has been locked.
Support Specialist
Stefan,
Since it sounds like you already know the template file you're working with (since you have the $this->item property), it's mainly a matter of adding the following tags. You'll want to add the in an HTML area (not inside of PHP code):
{JFBCGraph image=<?php echo $this->item->image; ?>}
{JFBCGraph description=<?php echo $this->item->image_caption; ?>}
The only thing I'm not sure of is if the item->image is the full page to the image (including domain), or not. If it's a relative path, then you'll need to add the domain, like so:
{JFBCGraph image=<?php echo JURI::root().$this->item->image; ?>}
Hope that helps, but if you need more info, just let us know!

Alex
The topic has been locked.
Active Subscriptions:

None
Hi Alex,

Thanks, the code works, the meta properties display correctly in the source code.

However, there seems to be a small anomaly: Although the right picture link shows in the source code and also that link shows the right picture, sometimes a different picture is posted to Facebook or no picture is posted at all. There is also no second image property in the page.

I set "Use first image in article for default" to "No" which should be the right setting I assume. Any chance that this function creates a confusion?
Can you navigate me to the piece of code/function where the first image of the page is pulled, so I can deactivate the respective lines for testing purposes?

Thanks
Stefan
The topic has been locked.
Active Subscriptions:

None
12 years 2 weeks ago #21161 by mtk

anexgo wrote: Hi Alex,

Thanks, the code works, the meta properties display correctly in the source code.

However, there seems to be a small anomaly: Although the right picture link shows in the source code and also that link shows the right picture, sometimes a different picture is posted to Facebook or no picture is posted at all. There is also no second image property in the page.

I set "Use first image in article for default" to "No" which should be the right setting I assume. Any chance that this function creates a confusion?
Can you navigate me to the piece of code/function where the first image of the page is pulled, so I can deactivate the respective lines for testing purposes?

Thanks
Stefan

Hello Stefan,
this might be a simple cache issue.
please check the website with the FB Debug Tool before posting anything to FB and see if that helps.

Mati
The topic has been locked.
Active Subscriptions:

None
11 years 11 months ago #22796 by azwanz
HI, do you have any idea where can I add this

{JFBCGraph image=item->image; ?>}
{JFBCGraph description=item->image_caption; ?>}

in any of K2 article automatically. I dont want to insert it everytime when I create an Item in K2.
The topic has been locked.
Support Specialist
azwanz,
The template directory for K2 is where you'd want to add the tags. Likely, the specific 'item' template file on your site would be '/components/com_k2/templates/default/item.php' In there, you'd need to find the right section that's inserting the image and use the same PHP variables in the tags, as described in my post above.

Hope that helps, but if you run into issues or have questions, let us know!

Thanks,
Alex
The topic has been locked.