Adding Facebook "Like" Button

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

cozbaldwin2
Posts: 19
Joined: Thu Apr 22, 2010 3:26 pm

Adding Facebook "Like" Button

Post by cozbaldwin2 »

I can't seem to figure out how to get the Facebook "Like" button added to each article.
Please take a look at what they provide. We're looking for a way to include the current page's URL into the iframe source:
<iframe src="http://www.facebook.com/plugins/like.php?HTTP://CURRENT_PAGE_URL&layout=standard&show_faces=true&width=450&action=like&font=trebuchet+ms&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:100px"></iframe>
Is this possible? If so, how?

Thanks.
Thorsten
Posts: 15729
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Adding Facebook "Like" Button

Post by Thorsten »

Hi,

you could add this in the template with an additional template variable for the URL in the iFrame. Here's how you can do this: http://faq.phpmyfaq.de/content/11/48/en ... ework.html

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
cozbaldwin2
Posts: 19
Joined: Thu Apr 22, 2010 3:26 pm

Re: Adding Facebook "Like" Button

Post by cozbaldwin2 »

Ok. This is a little over my head, but I THINK I understand.
Let's see if I have this straight:

* In the test.php, would my content go between these single-quotes:

Code: Select all

$testContent = '';
?

* And what would my content be, exactly? Something like:

Code: Select all

<?php echo $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; ?>
?

* Then register the variable in config/constants.php maybe called "getUrl" ?

* And then, once I get those two things worked out, my Like Button iFrame code would then look like:
<iframe src="http://www.facebook.com/plugins/like.ph ... heme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:100px"></iframe>
This all look right?
Thorsten
Posts: 15729
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Adding Facebook "Like" Button

Post by Thorsten »

Hi,

looks okay.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
cozbaldwin2
Posts: 19
Joined: Thu Apr 22, 2010 3:26 pm

Re: Adding Facebook "Like" Button

Post by cozbaldwin2 »

Nope. The error when clicking the Like button says "The page at http://%7BgetUrl%7D could not be reached." so it's not even getting past that command and its rendering it as text, i guess.
Thorsten
Posts: 15729
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Adding Facebook "Like" Button

Post by Thorsten »

Hi,

you forgot the processTemplate() stuff, that's why your template variable {getUrl} isn't rendered.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
cozbaldwin2
Posts: 19
Joined: Thu Apr 22, 2010 3:26 pm

Re: Adding Facebook "Like" Button

Post by cozbaldwin2 »

No, that's all in there. Let me show you what I have: (please note, Instead of "test" i have been using getUrl for everything.)

So when I tried looking at index.php?action=getUrl i saw the php echo $_SERVER thing was being printed and not rendered either. So I started using "<script>document.write(location.href);</script>" in the writeContent. This works when I view the new page.

Still, the Like button is not rendering {getUrl}.

Here's all I have:


getUrl.php (placed in FAQ root):

Code: Select all

<?php

$getUrlTitle = 'Get The URL!';
$getUrlContent = '<script>document.write(location.href);</script>';

for($i=0; $i<10; $i++) {
    $getUrlContent .= 'Line '.$i.'<br />';
}


$tpl->processTemplate ('writeContent', array(
                            'getUrlTitle'     => $getUrlTitle,
                            'getUrlContent'   => $getUrlContent
                            )
                        );
$tpl->includeTemplate('writeContent', 'index');
?>
getUrl.tpl (placed in faq/template/ directory):

Code: Select all

<!-- Start Test Content -->
  <h2>{getUrlTitle}</h2>
    <span>{getUrlContent}</span>
    <!-- End Test Content -->

And in inc/constants.php I now have:

Code: Select all

$allowedVariables = array(
    'add'               => 1,
    'artikel'           => 1,
    'ask'               => 1,
    'contact'           => 1,
    'help'              => 1,
    'instantresponse'   => 1,
    'mailsend2friend'   => 1,
    'news'              => 1,
    'open'              => 1,
    'register'          => 1,
    'save'              => 1,
    'savecomment'       => 1,
    'savequestion'      => 1,
    'savevoting'        => 1,
    'search'            => 1,
    'send2friend'       => 1,
    'sendmail'          => 1,
    'show'              => 1,
    'sitemap'           => 1,
    'thankyou'          => 1,
    'translate'         => 1,
    'writecomment'      => 1,
	'getUrl'      => 1,
);
Now, in your tutorial, you said this should go in "config/constants.php" -- but I'm guessing that was for an older version of phpMyFaq. I only see constants.php in INC directory. Should it be somewhere else?
Thorsten
Posts: 15729
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Adding Facebook "Like" Button

Post by Thorsten »

HI,

the link was for the current stable 2.6 version, if your constants.php file is in inc/, then you're using 2.0 or 2.5.

I think you don't need a new file, just a new template variable.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
cozbaldwin2
Posts: 19
Joined: Thu Apr 22, 2010 3:26 pm

Re: Adding Facebook "Like" Button

Post by cozbaldwin2 »

Argh, yes - I'm running 2.5.2, sorry.

Could you be a little more specific in what I need to do now, please?
Thorsten
Posts: 15729
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Adding Facebook "Like" Button

Post by Thorsten »

Hi,

open template/artikel.tpl and add the following where you like to:

Code: Select all

<iframe src="http://www.facebook.com/plugins/like.php?href={getCurrentUrl}&layout=standard&show_faces=true&width=450&action=like&font=trebuchet+ms&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:100px"></iframe>
Then open artikel.tpl and change the template variable array, look for the line

Code: Select all

    'writeComments'                 => $comment->getComments($record_id, PMF_Comment::COMMENT_TYPE_FAQ)));
and change it to

Code: Select all

    'writeComments'                 => $comment->getComments($record_id, PMF_Comment::COMMENT_TYPE_FAQ),
    'getCurrentUrl'                 => urlencode($facebookUrl)));
Nothing else to do and it works. :-)

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
cozbaldwin2
Posts: 19
Joined: Thu Apr 22, 2010 3:26 pm

Re: Adding Facebook "Like" Button

Post by cozbaldwin2 »

This is really annoying, I know. But that did not work.
Facebook has not made this as easy as they could have, I don't believe.

Now when I click on the Like button, it tells me:
"You must specify an URL as part of this widget or API."

If it helps, I was able to get it working in Wordpress by putting "<?php the_permalink() ?>" in the iFrame's query string as the href=.
I tried <?php getCurrentUrl() ?> in hopes that would work... but it didnt.
Thorsten
Posts: 15729
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Adding Facebook "Like" Button

Post by Thorsten »

Hi,

how does it look like now in your page? I tested it yesterday and it worked.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
cozbaldwin2
Posts: 19
Joined: Thu Apr 22, 2010 3:26 pm

Re: Adding Facebook "Like" Button

Post by cozbaldwin2 »

Well it LOOKS fine. It's always looked fine. But when you actually Click it, the word ERROR appears. Clicking the word Error will launch a pop-up and show you what it's having a problem with. First was the invalid URL. Now it's saying it's not seeing (I have not specified) a URL.
Thorsten
Posts: 15729
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Adding Facebook "Like" Button

Post by Thorsten »

Hi,

can I check your code online?

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Post Reply