Callam
Callam

Reputation: 1009

Adding unique fb like button to dynamically loaded content

I need to add a facebook like button to menu items from a php cp menu –

I’m thinking of pulling in the information from each menu div and having it fill in meta data before sending it to facebook

<div class="menu_content_cell">
<span class="menu_title"><?php echo $menuItem['item_name']?></span>
<?php if($menuItem['item_desc']) {?>                                                    <br />
<span class="menu_description"><?php echo $menuItem['item_desc']?></span><?php } ?>
</div>

to fill in

      <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:og="http://ogp.me/ns#"
      xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
    <title>Sample</title>
    <meta property="og:title" content="Site Name <?php echo $menuItem['item_name']?>"/>
    <meta property="og:type" content="food"/>

    <meta property="og:site_name" content="Site Name"/>
    <meta property="og:description"
          content="<?php echo $menuItem['item_desc']?>"/>

    <meta http-equiv="refresh" content="0;url=http://www.sample.com/menu.php"/>
  </head>

<body>
</body>
</html>

is this possible, or am I barking up the wrong tree?

How would I do it? Maybe if I could get a unique id for each menu item - I'm sure this is possible but I'm struggling to piece the parts of the puzzle together

Thanks in Advance

Upvotes: 1

Views: 634

Answers (2)

Buddhi
Buddhi

Reputation: 2324

use fb open graph meta tag og:type and set it as "article" for your dynamic page html header

<meta property="og:type" content="article"/>

other fb opengraph meta tags

<meta property="og:title" content="your dynamic title">
<meta property="og:image" content="your dynamic image url">
<meta property="og:url" content="your dynamic page url">
<meta property="og:description" content="your dynamic content">

Upvotes: 0

Nitzan Tomer
Nitzan Tomer

Reputation: 164177

Facebook indexes objects by urls, different urls mean different objects in their graph.

For example, these pages will be considered different:

And so, you should differentiate pages which you want users to like by their urls, and based on the dynamic part (either using query string or pretty urls) output different og tags on the server side.

Upvotes: 1

Related Questions