I've been a PHP developer for long time, but I am new to Joomla. On a Joomla 2.5 project, I need to make open graph meta tags. As a part of open graph meta tags, I need to find first image of article. I tried many, many ways suggested in forums and articles, but none of them worked.
This is a sample of what I tested in template file:
$article = & JTable::getInstance("content");
$article->load(JRequest::getInt("id"));
$url = JURI::current();
$title = $article->get("title");
if (strpos(".html", $url) != 0) {
$type = "website";
} else {
$type = "aricle";
} //opengraph
$article_images = $article->get("images");
$pictures => json_decode($article_images);
$timage= $pictures->{'image_intro'};
?>
<meta property="og:title" content="<?php echo $title ?>" />
<meta property="og:type" content="<?php echo $type ?>" />
<meta property="og:url" content="<?php echo $url ?>" />
<meta property="og:site_name" content="beytoote" />
<meta property="og:image" content="<?php echo $timage ?>" />
but it did not worked.
And this is a sample of what I tested inside a block:
<?php //opengraph $doc = JFactory::getDocument();
if (preg_match('/<\s*img[^>]+>/Ui', $this->item->text, $matches)) {
$image=$matches[1]
}
$doc->addCustomTag( '<meta property="og:image" content="' . $image . '">' );
?>