Last active
August 29, 2017 23:03
-
-
Save davidjguru/56797250c2ee332546c0d22a9b0119f2 to your computer and use it in GitHub Desktop.
I don't need a unique widget for the whole website. I need N Facebook PagePlugin widgets to display within M nodes of a specific content type.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First, I've created a new text field for the content type called facebook_direction. | |
# Second, I got the facebook script given by Facebook Developers. | |
# Third, I wrote some PHP code for get the info about the current node and | |
# processing the field values asociated to the node. | |
# Fourth, I've changed the URL values from the snippet with PHP code to get | |
# every facebook page from every node. | |
# Fifth, I made a new custom block in my Drupal site, called "facebook stream widget" | |
# 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 | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment