How to display current URL on page?

I'm trying to add a facebook comment block on pages, found here: http://developers.facebook.com/docs/reference/plugins/comments/

 

The problem is, the href part of the code.

<div class="fb-comments" data-href="http://www.mydomain.com" data-num-posts="2" data-width="470"></div>

You have to enter your page URL, but the problem is, I want the comment box on more then one page, so using href="http://www.mydomain.com"will not work, because all comments are being left for the main page, but shown on the other pages. Is there something I can do within Dolphin to include the current page the visitor is on? Something like href="http://www._currentpage.com", where _currentpage is defined like in the header.inc.php?

 

I hope I'm making myself clear.

 

something like this would work, but only works in php files, so It won't work in the template files


data-href="<%
Thispage ="http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")
%>
" data-num-posts="2" data-width="470">


Quote · 2 Sep 2012

I created a php block using Deanos tools with the following code:

echo '<div class=fb-comments data-href=http://www.mydomain.com data-num-posts=2 data-width=470></div>';

echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']';

 

the first code DOES show the comment box, and the second code DOES print out the URL, but when I try to change the domain in my first code to data-href=http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] it doesn't work. Anyone have any ideas what would work?

Quote · 2 Sep 2012

 

I created a php block using Deanos tools with the following code:

$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $url;


echo '<div class=fb-comments data-href=$url data-num-posts=2 data-width=470></div>';

 

It prints out the URL of the page correctly, but it's not inserting it correctly into the data-href=$url. I've almost got it. I don't understand why the first $url will display the URL, but the second $url is not inserting correctly

It's all in the method of your quoting.

PHP variables cannot be used as is in strings that are quoted with single quotes. PHP processes things differently depending on the type of quotes used.

Most common single quotes are used because double quotes can be part of the string without having to escape them. With double quotes, other quotes in the string have to be escaped.

Then of course there is the heredoc method. But i am not going to get into trying to teach php.


Try one of these.

echo "<div class=fb-comments data-href={$url} data-num-posts=2 data-width=470></div>";

Or

echo '<div class=fb-comments data-href=' . $url . ' data-num-posts=2 data-width=470></div>';


I prefer the last method i used. I believe it is more common.


https://www.deanbassett.com
Quote · 2 Sep 2012

Deano, you're a life saver, I was ripping my hair out, and your fix worked. Thanks!!

 

I want to add this block to a few pages, do I have to create a new php for every page, or is there a way to include the 1 php block I've already created?

Quote · 2 Sep 2012

New block for each page.

https://www.deanbassett.com
Quote · 2 Sep 2012

hello
I tried to put in a php block:

echo "<div class=fb-comments data-href={$url} data-num-posts=2 data-width=470> </ div>";

or

echo '<div class = fb-comments data-href ='. $ url. 'Data-num-posts-data = 2 width = 470> </ div>';

but it does not work
I have an error message:
Warning: http://invalid.invalid/ is not reachable.

What should I do???
thank you

Quote · 10 Dec 2012

I am guessing your missing a piece. You have to load $url with something. You only posted one line of code, so if you have more than that, post it all. We have to see what you have to determine whats wrong with it.

Something like this needs to come first.

$url = BX_DOL_URL_ROOT . $_SERVER['REQUEST_URI'];

If you need help with code issues, post all of the code your using in the block.

https://www.deanbassett.com
Quote · 10 Dec 2012

Hello

I use the facebook code :

<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/fr_FR/all.js#xfbml=1&appId=300946363293367";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script>

And :

<div class="fb-comments" data-href="http://example.com" data-width="470" data-num-posts="2"></div>

but I would like to customize the url that will be the URL of the page that is share on facebook,I thought  I could using the code you gave above

sorry for my english, I use google translator :)

 

Quote · 11 Dec 2012

I'm having the same issue.  I need to allow each page to have its unique comments.  but i cant seem to get it done. all comments show on all pages.

I tried with PHP box & with html box.

In templates/base/_footer.html file, I placed the Javascript DSK code provided by FB :

<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>

 

In an HTML box, I placed : 

<div class="fb-comments" data-href="http://www.bdumbdum.com" data-width="700" data-num-posts="15"></div>

At a loss on how I can make this unique comments box per page, either using HTML or PHP block.

Help?

Quote · 30 Jan 2013

 

In an HTML box, I placed : 

<div class="fb-comments" data-href="http://www.bdumbdum.com" data-width="700" data-num-posts="15"></div>

At a loss on how I can make this unique comments box per page, either using HTML or PHP block.

Help?


You have two ways.

1) Use in a html block and make sure this http://www.bdumbdum.com is the full URL to the page it is on.

2) Or use in a PHP block and have PHP generate the code like so.

echo '<div class="fb-comments" data-href="' . BX_DOL_URL_ROOT . $_SERVER['REQUEST_URI'] . '" data-width="700" data-num-posts="15"></div>';

Using php is best as you can use the same code on every page because PHP figures out the URL for you. If you use HTML then you have to do the url by hand.

Thats why all your comment boxes have the same content, because if your using http://www.bdumbdum.com then the url is the same. Each page has to be different like http://www.bdumbdum.com/m/photos/home/ or http://www.bdumbdum.com/m/files/home/


Thats what newton tried to explain in this topic. http://www.boonex.com/forums/topic/Right-I-m-an-idiot-and-need-help-.htm Each needs to have a unique URL.


https://www.deanbassett.com
Quote · 30 Jan 2013

Deano.  I tried your suggestion and got :

Parse error: syntax error, unexpected $end, expecting ',' or ';' in/home/bdumbdum/public_html/inc/classes/BxDolPageView.php(666) : eval()'d code on line 1

Quote · 30 Jan 2013

 

Deano.  I tried your suggestion and got :

Parse error: syntax error, unexpected $end, expecting ',' or ';' in/home/bdumbdum/public_html/inc/classes/BxDolPageView.php(666) : eval()'d code on line 1

 I edited the post. Was missing the ; at the end of the line of php code. Guess PHP is not you thing.

https://www.deanbassett.com
Quote · 30 Jan 2013

Lol - no, php is not my thing!

Thank you so much, sir, i rely on smart biscuits like yourself to guide me!  

Worked perfectly.

Quote · 30 Jan 2013

Hello you've done a great job and I want congratulate you... Now can you help me? 
I have a doubt, I've done everything you've recommended in this forum. 

1.- I downloaded your plugin module Deanos Tools and have installed in my dolphin site
2.- I created and inserted a new Php block into the pages
3.- I placed the code for the facebook comments box, into the Php Block, like as you have recommended. "CODE1"

echo '<div class="fb-comments" data-href="' . BX_DOL_URL_ROOT . $_SERVER['REQUEST_URI'] . '" data-width="700" data-num-posts="15"></div>'; 

Here Everything is perfect, so good. I have set up the facebook comment box and I can view it properly in my site, 
but the problem is, What to do with the rest of the code that gives me facebook in (https://developers.facebook.com/docs/reference/plugins/comments/)
like: "CODE2"

<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_LA/all.js#xfbml=1&appId=133998745755643";

  fjs.parentNode.insertBefore(js, fjs);

}(document, 'script', 'facebook-jssdk'));</script>


Because, Could it be the reason why I can not see the "link configuration" and "link Admin View Moderator"? 
because, this code has not been added in any part of the site. 

Please see this Image With Moderator link View and Config Admin Link: 

And Now see the image "without" Link moderator view and Config Admin
like in my site with yours recommendations (Php Block): 
Example: http://www.ruddypalmar.com/m/sounds/view/anotherfeel

Can you tell me where should I put the above code "CODE2" to see links moderator
and setup in facebook comment box? 


thanks for your support and for your patience.

Kind regards. 
lamenteinc  

www.RuddyPalmar.com

 

 

In an HTML box, I placed : 

<div class="fb-comments" data-href="http://www.bdumbdum.com" data-width="700" data-num-posts="15"></div>

At a loss on how I can make this unique comments box per page, either using HTML or PHP block.

Help?


You have two ways.

1) Use in a html block and make sure this http://www.bdumbdum.com is the full URL to the page it is on.

2) Or use in a PHP block and have PHP generate the code like so.

echo '<div class="fb-comments" data-href="' . BX_DOL_URL_ROOT . $_SERVER['REQUEST_URI'] . '" data-width="700" data-num-posts="15"></div>';

Using php is best as you can use the same code on every page because PHP figures out the URL for you. If you use HTML then you have to do the url by hand.

Thats why all your comment boxes have the same content, because if your using http://www.bdumbdum.com then the url is the same. Each page has to be different like http://www.bdumbdum.com/m/photos/home/ or http://www.bdumbdum.com/m/files/home/


Thats what newton tried to explain in this topic. http://www.boonex.com/forums/topic/Right-I-m-an-idiot-and-need-help-.htm Each needs to have a unique URL.


 

Quote · 1 Feb 2013

 Hi again.

I implemented the PHP option you referred and that works perfectly - i.e.. each page now has it's own FB comments box.  And when someone makes a comment or uses FB's 'like' button, it shares my page link on their FB profile, which is exactly what I want.

But there's a problem I can't get around - Facebook is not picking up the page image.  When checking on FB's debug tool it doenst seem to understand where to find the 

<meta property="og:image"  content="">   

<meta property="og:description" content="">  

What tag should I be using in content=""??

I have FB's own comments box and 'Like' button inside the page.  Neither share 'description' or 'image' properly.

I also have the AddThis buttons at the top of the page - and AddThis shares the photo thumbnail, title and description perfectly.  So where am I going wrong?  Why is FB so blimmin complicated?

Help anyone?

 

 

 

In an HTML box, I placed : 

<div class="fb-comments" data-href="http://www.bdumbdum.com" data-width="700" data-num-posts="15"></div>

At a loss on how I can make this unique comments box per page, either using HTML or PHP block.

Help?


You have two ways.

1) Use in a html block and make sure this http://www.bdumbdum.com is the full URL to the page it is on.

2) Or use in a PHP block and have PHP generate the code like so.

echo '<div class="fb-comments" data-href="' . BX_DOL_URL_ROOT . $_SERVER['REQUEST_URI'] . '" data-width="700" data-num-posts="15"></div>';

Using php is best as you can use the same code on every page because PHP figures out the URL for you. If you use HTML then you have to do the url by hand.

Thats why all your comment boxes have the same content, because if your using http://www.bdumbdum.com then the url is the same. Each page has to be different like http://www.bdumbdum.com/m/photos/home/ or http://www.bdumbdum.com/m/files/home/


Thats what newton tried to explain in this topic. http://www.boonex.com/forums/topic/Right-I-m-an-idiot-and-need-help-.htm Each needs to have a unique URL.


 

Quote · 7 Feb 2013
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.