CONTROL IMAGES ON FACEBOOK STATUS POSTS?

5 posts by 2 authors in: Forums > CMS Builder
Last Post: April 22, 2013   (RSS)

By csdesign - April 22, 2013

Hello! :)

Okay, so I have one more thing for today. 

When posting a status update on facebook with a link to the homepage - I would like to be able to choose from a specific set of image uploads to use as the image options for that post. 

I found this article on the subject: Controlling the Facebook Image and Text with Meta Tags
http://www.hyperarts.com/blog/how-to-control-facebook-image-thumbnail-text-popup-dialogs/

It said to use this tag in the head tag: 

<link rel="image_src" href="http://URL-TO-YOUR-IMAGE" / >

I've tried some variations on this but always get an error in my source code. Here's my current attempt and below that, the error I'm receiving in the source code: 
I attemped it with just the  <link rel="image_src" href="<?php echo $upload['urlPath'] ?>" / > line, but that didn't work either. 

This is the head code for my include_header.php page.
There is a featured image section that is on every page.  I want to use that for the image selections or I could create a new gallery just for fb posting. 

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/content/99/9303799/html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records from 'products_featured'
list($products_featuredRecords, $products_featuredMetaData) = getRecords(array(
'tableName' => 'products_featured',
'perPage' => '3',
'orderBy' => 'RAND()',
'loadUploads' => true,
'allowSearch' => false,
));

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-language" content="en-US" />

<?php foreach ($products_featuredRecord['images'] as $index => $upload): ?>
<link rel="image_src" href="<?php echo $upload['urlPath'] ?>" / >
<?php endforeach ?>

SOURCE CODE ERRORS:

Notice: Undefined variable: products_featuredRecord in /home/content/99/9303799/html/include_header.php on line 28
Warning: Invalid argument supplied for foreach() in /home/content/99/9303799/html/include_header.php on line 28

THANKS SO MUCH FOR THE HELP!!  Tina

By gregThomas - April 22, 2013

Hi Tina, 

I think the problem is that the getRecords function is returning an array of 3 products_featured, and it looks as if you're not looping through them first, if you modify your code like this, it should work:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-language" content="en-US" />

<?php foreach($products_featuredRecords as $products_featuredRecord: ?>
  <?php foreach ($products_featuredRecord['images'] as $index => $upload): ?>
    <link rel="image_src" href="<?php echo $upload['urlPath'] ?>" / >
  <?php endforeach ?>
<?php endforach; ?>

So the page loops through each products_featured record, then loops through each products images.

Let me know if you have any questions.

Cheers!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By csdesign - April 22, 2013 - edited: April 22, 2013

Thanks for the help, Greg! 

I added a ")" after the"Record" in the first line and I also changed "endforach" to "endforeach" in the last line

<?php foreach($products_featuredRecords as $products_featuredRecord): ?>
<?php foreach ($products_featuredRecord['images'] as $index => $upload): ?>
<link rel="image_src" href="<?php echo $upload['urlPath'] ?>" / >
<?php endforeach ?>
<?php endforeach; ?>

 Off to test in facebook now that all the errors are gone! :) 

By gregThomas - April 22, 2013

Woops! It needs more brackets:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-language" content="en-US" />

<?php foreach($products_featuredRecords as $products_featuredRecord): ?>
  <?php foreach ($products_featuredRecord['images'] as $index => $upload): ?>
    <link rel="image_src" href="<?php echo $upload['urlPath'] ?>" / >
  <?php endforeach ?>
<?php endforeach; ?>

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com