0
votes

I'm trying to set up the Drupal 7 Facebook Page Plugin module, and everything ok, it works fine.

My problem is this: I do not need a unique widget for the whole website. I need N Facebook PagePlugin widgets to display within M nodes of a specific content type. I have a content type "companies" and I need that in each profile created of company, the configuration of this widget is available in a segmented way. (1 node "company" = 1 facebook page plugin widget).

Is there any way to do this for each node? Does each node show a block from facebook page plugin configured ad-hoc?

Code? Site-building?

Greetings to all

1
Throw away the module, and simply place the necessary FB code in a custom template for this node type ...? - CBroe
Each client will be the drupal editor user who creates their company profile. It is not intuitive to ask them to generate the code and insert it. Best to do it automatically: request the link to Facebook page through a field in the form and then insert it into the widget settings, but I don't know if this is possible : - / - davidjguru
Who said anything about letting them do that? Are you using different templates for each company, or what? And adding another field to your custom node type should not really be a challenge. - CBroe

1 Answers

0
votes

Ok, mission accomplished. I only used six (or seven :-P) parts:

  1. First, I've created a new text field for the content type called facebook_direction.
  2. Second, I got the facebook script given by Facebook Developers.
  3. Third, I wrote some PHP code for get the info about the current node and processing the field values asociated to the node.
  4. Fourth, I've changed the URL values from the snippet with PHP code to get every facebook page from every node.
  5. Fifth, I made a new custom block in my Drupal site, called "facebook stream widget"

  6. Sixth, I've inserted the code in the custom block body with PHP editor active, marking the block as only for content types of kind "companies".

Add: I made sure that only the Facebook widget view is created yes and only if the node has completed its field facebook direction. Otherwise, the widget is not generated (line if (!is_null($direction)) ), so it does not show it empty.

Here is the code and works fine:

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/es_ES/sdk.js#xfbml=1&version=v2.10";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<?php

$field = 'field_facebook_direction';
$node = menu_get_object();
$items = field_get_items('node', $node, $field);
$direction = $items[0]['value'];
 if (!is_null($direction)) {
?>
<div class="fb-page" data-adapt-container-width="true" data-hide-
cover="false" data-href="<?php
 echo $direction;?>" data-show-facepile="false" data-small-
header="false" data-tabs="timeline">

<blockquote cite="<?php echo $direction;?>" class="fb-xfbml-parse-
ignore">
<a href="<?php echo $direction;?>">Facebook  Stream</a></blockquote>
</div>

<?php
}

?>

Greetings from Seville! :-)