- Posts: 2
COMMUNITY FORUM
RE: K2 Facebook Comment Box
- Elmer Balbin
-
Topic Author
- Offline
- New Member
Less
More
11 years 11 months ago - 11 years 11 months ago #114521
by Elmer Balbin
<?php endif; ?>
RE: K2 Facebook Comment Box was created by Elmer Balbin
Greetings K2,
I have recently went around the community forums and found a solution to my problem regarding how to implement the Facebook comment box replacing the standard K2 comment box of items.
Now my only problem is on how to display the comments of PER item. What I mean is to display comments only for the specific item and not all comments from a single site. Below is the attached code. If I understand the code correctly, it only displays the comments from the 'data-href'. In this case, www.example.com/blog/item-1.
How can I make comments for each item since this is a global overide of all the Items? Any help would be appreciated!
<?php if($this->item->params->get('itemComments') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2')) && empty($this->item->event->K2CommentsBlock)): ?>
<!-- Item comments -->
<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/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-comments" data-href="www.example.com/blog/item-1" data-width="500" data-num-posts="10">
I have recently went around the community forums and found a solution to my problem regarding how to implement the Facebook comment box replacing the standard K2 comment box of items.
Now my only problem is on how to display the comments of PER item. What I mean is to display comments only for the specific item and not all comments from a single site. Below is the attached code. If I understand the code correctly, it only displays the comments from the 'data-href'. In this case, www.example.com/blog/item-1.
How can I make comments for each item since this is a global overide of all the Items? Any help would be appreciated!
<?php if($this->item->params->get('itemComments') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2')) && empty($this->item->event->K2CommentsBlock)): ?>
<!-- Item comments -->
<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/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-comments" data-href="www.example.com/blog/item-1" data-width="500" data-num-posts="10">
<?php endif; ?>
Please Log in or Create an account to join the conversation.
- Elmer Balbin
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 2
11 years 11 months ago #114522
by Elmer Balbin
Replied by Elmer Balbin on topic Re: RE: K2 Facebook Comment Box
Nevermind, I got it! :D For those who are looking for the same thing here's what I done. I simply changed the value of data-href to a php function that retrieves the current address.
Here is the updated code:
<?php if($this->item->params->get('itemComments') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2')) && empty($this->item->event->K2CommentsBlock)): ?>
<!-- Item comments -->
<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/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-comments" data-href="<?php $url="http://".$_SERVER.$_SERVER; echo $url; ?>" data-width="500" data-num-posts="10"></div>
<?php endif; ?>
Here is the updated code:
<?php if($this->item->params->get('itemComments') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2')) && empty($this->item->event->K2CommentsBlock)): ?>
<!-- Item comments -->
<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/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-comments" data-href="<?php $url="http://".$_SERVER.$_SERVER; echo $url; ?>" data-width="500" data-num-posts="10"></div>
<?php endif; ?>
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
11 years 11 months ago #114523
by Krikor Boghossian
Replied by Krikor Boghossian on topic [SOLVED] RE: K2 Facebook Comment Box
Hello Elmer,
That will work but you can always try $this->item->absoluteURL; instead of $_SERVER.$_SERVER; echo $url.
That will work but you can always try $this->item->absoluteURL; instead of $_SERVER.$_SERVER; echo $url.
Please Log in or Create an account to join the conversation.
- Stonedfury
-
- Offline
- New Member
Less
More
- Posts: 12
11 years 11 months ago #114524
by Stonedfury
Replied by Stonedfury on topic Re: [SOLVED] RE: K2 Facebook Comment Box
Is this on the item view page? I am looking for the same thing. :)
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
11 years 11 months ago #114525
by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: RE: K2 Facebook Comment Box
Yes. in item.php
For more information on overriding please read this tutorial getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
and be sure to watch these videos getk2.org/documentation/k2class2012
For more information on overriding please read this tutorial getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
and be sure to watch these videos getk2.org/documentation/k2class2012
Please Log in or Create an account to join the conversation.
- Christian Matthew
-
- Offline
- New Member
Less
More
- Posts: 15
11 years 10 months ago #114526
by Christian Matthew
Replied by Christian Matthew on topic Re: RE: K2 Facebook Comment Box
guys can you comment on this a little more as I have no idea how to do this or where you got your information from?
thanks
thanks
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
11 years 10 months ago #114527
by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: RE: K2 Facebook Comment Box
Hello Christian
The url where you can generate the facebook comments code is developers.facebook.com/docs/reference/plugins/comments/
Remember to fill in the data-href="" attribute with the <?php echo $this->item->absoluteURL; ?> variable.
You also need to read this mini tutorial on overriding on order to understand which file you need to edit.
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
The url where you can generate the facebook comments code is developers.facebook.com/docs/reference/plugins/comments/
Remember to fill in the data-href="" attribute with the <?php echo $this->item->absoluteURL; ?> variable.
You also need to read this mini tutorial on overriding on order to understand which file you need to edit.
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Please Log in or Create an account to join the conversation.
- Christian Matthew
-
- Offline
- New Member
Less
More
- Posts: 15
11 years 10 months ago #114528
by Christian Matthew
Replied by Christian Matthew on topic Re: RE: K2 Facebook Comment Box
i went with jfbconnect which adds the functionality if I need but moreover i went with discuss because it is better IMHO and uses facebook login if the user wants.
Please Log in or Create an account to join the conversation.
- Shiv240
-
- Offline
- New Member
Less
More
- Posts: 14
10 years 9 months ago - 10 years 9 months ago #114529
by Shiv240
Replied by Shiv240 on topic Re: RE: K2 Facebook Comment Box
Genius Elmer Balbin !
But i didn't get what is absolute url.
$this->item->absoluteURL??
But i didn't get what is absolute url.
$this->item->absoluteURL??
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 9 months ago #114530
by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: RE: K2 Facebook Comment Box
The item's absolute url which is needed for the comments to work properly.
The regular one is relative to the site and will not work properly.
Absolute urls start with www.example.com/....
The regular one is relative to the site and will not work properly.
Absolute urls start with www.example.com/....
Please Log in or Create an account to join the conversation.