Keyword

Open Graph protocol tags in templates articles K2

  • Andrii Natalukha
  • Andrii Natalukha's Avatar Topic Author
  • Offline
  • New Member
More
12 years 10 months ago - 12 years 10 months ago #59064 by Andrii Natalukha
Open Graph protocol tags in templates articles K2 was created by Andrii Natalukha
How to implement the Open Graph protocol insert tags into your template articles K2?

<html xmlns="www.w3.org/1999/xhtml"
xmlns:og="ogp.me/ns#"
xmlns:fb="www.facebook.com/2008/fbml">
<head>
<title>The Rock (1996)</title>
<meta property="og:title" content="The Rock"/>
<meta property="og:type" content="movie"/>
<meta property="og:url" content="www.imdb.com/title/tt0117500/"/>
<meta property="og:image" content="ia.media-imdb.com/rock.jpg"/>
<meta property="og:site_name" content="IMDb"/>
<meta property="fb:admins" content="USER_ID"/>
<meta property="og:description"
content="A group of U.S. Marines, under command of
a renegade general, take over Alcatraz and
threaten San Francisco Bay with biological
weapons."/>
...
</head>
...
</html>


Here's how it is implemented in templates for GavickPro Joomla-articles:

// OpenGraph support
$template_config = new JConfig();
$uri = JURI::getInstance();
$article_attribs = json_decode($this->item->attribs, true);

$og_title = $this->escape($this->item->title);
$og_type = 'article';
$og_url = $cur_url;
$og_image = '';
$og_site_name = $template_config->sitename;
$og_desc = '';

if(isset($article_attribs)) {
$og_title = ($article_attribs == '') ? $this->escape($this->item->title) : $this->escape($article_attribs);
$og_type = $this->escape($article_attribs);
$og_url = $cur_url;
$og_image = ($article_attribs == '') ? '' : $uri->root() . $article_attribs;
$og_site_name = ($article_attribs == '') ? $template_config->sitename : $this->escape($article_attribs);
$og_desc = $this->escape($article_attribs);
}

$doc = JFactory::getDocument();
$doc->setMetaData( 'og:title', $og_title );
$doc->setMetaData( 'og:type', $og_type );
$doc->setMetaData( 'og:url', $og_url );
$doc->setMetaData( 'og:image', $og_image );
$doc->setMetaData( 'og:site_name', $og_site_name );
$doc->setMetaData( 'og:description', $og_desc );

Please Log in or Create an account to join the conversation.

More
12 years 10 months ago - 12 years 10 months ago #59065 by troponin
  • Andrii Natalukha
  • Andrii Natalukha's Avatar Topic Author
  • Offline
  • New Member
More
12 years 10 months ago #59066 by Andrii Natalukha
Replied by Andrii Natalukha on topic Re: Open Graph protocol tags in templates articles K2
Thank you very much!
I found a post:

JoomlaWorksPermalink Reply by JoomlaWorks on April 27, 2011 at 11:17pm
Just a heads up that we plan to add Facebook meta tags in v2.5 of K2.


Why has not it? :(

Please Log in or Create an account to join the conversation.

More
12 years 5 months ago #59067 by Matthew Gray
Thanks for that!!

Just a quick one...how can it be changed so that I can choose the 'S' or 'M' sized image instead of the document image?

Cheers,
Matt

Please Log in or Create an account to join the conversation.