I have the following code in template/page/html/head.phtml which tries it best to supply facebook with an apropriate sharing image.(og:image)
Everything works, except for the part that I'm trying to get the content text of a cms/page.
Logic dictates that if I use Mage::getSingleton('cms/page')->getContent()
that I should get the HTML content of the cms page being viewed.
However, 0 is returned to my function so I'm stuck with my default images on cms pages.
What am I doing wrong?
<?php
// viewing a product, get the image of the product for social sharing
if (Mage::registry('current_product'))
{
echo Mage::helper('catalog/image')->init(Mage::registry('current_product'), 'small_image')->resize(213);
}
// this is where I get nothing returned from the content of the current page being viewed.
elseif($cms_content = Mage::getSingleton('cms/page')->getContent())
{
$src = array();
$pos = 0;
while(strpos($cms_content,'<img ',$pos)!== false)
{
// do a lot of complicated stuff here, not relevant for question
}
$theone = isset($src[0]) ? $src[0] : false;
echo $theone;
}
// show default image
else
{
echo 'default image url';
}