Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I was wondering if I can include Facebook's php sdk file into a wordpress page template ?

For example in page.php:

<?php get_header(); ?>

    <?php get_sidebar(); ?>

        <!--BEGIN: wrapper-->
        <div class="wrapper">    
        <!--BEGIN: scrol left-->
        <div class="ppading">
            <div class="scroll-pane">

                      <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

                        <?php the_content(); ?>

                    <?php endwhile; ?>


            </div>
        </div><!--END: scrol left-->
        </div><!-- END: wrapper -->    
        <!--BEGIN: shadow-->
        <div id="shadow"></div>
        <!--END: shadow-->
<?php get_footer(); ?>

Can i attempt to include facebook.php like this:

<?php get_header(); ?>

    <?php get_sidebar(); ?>


    <?php


    session_start();
    echo "pass sds1";
    require_once TEMPLATEPATH.'/include/facebook.php';
    echo "pass";
    $config = array(
        "appId" => "XXXX",
        "secret" => "XXXX");

    $fb = new Facebook($config);
    echo $fb;
    $user = $fb->getUser();
    echo $user;
    ?>



        <!--BEGIN: wrapper-->
        <div class="wrapper">    
        <!--BEGIN: scrol left-->
        <div class="ppading">
            <div class="scroll-pane">

                      <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

                        <?php the_content(); ?>

                    <?php endwhile; ?>


            </div>
        </div><!--END: scrol left-->
        </div><!-- END: wrapper -->    
        <!--BEGIN: shadow-->
        <div id="shadow"></div>
        <!--END: shadow-->
<?php get_footer(); ?>

I've tried doing the above, but the echo "pass"; was not executed, this means that the require_once TEMPLATEPATH.'/include/facebook.php'; line has failed.

Can anyone advise me on how to achieve this ?

Thanks!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Try replacing this:

require_once TEMPLATEPATH.'/include/facebook.php';

...with this:

get_template_part( '/include/facebook.php' );

And if that doesn't work, try this:

locate_template( 'include/facebook.php', true );
share|improve this answer
    
hey good day and thanks for your reply. The facebook.php appears to be loaded. However, I dont see any thing printed out from $fb. It seems that the line $fb = new Facebook($config); is failing ( my app id and secret are correct as the same code is tested as a standalone script. Any ideas how to make the $fb = new Facebook($config); echo $fb; work ? thanks! –  DjangoRocks Jun 8 '12 at 17:38
    
That would probably be a separate question... –  Chip Bennett Jun 8 '12 at 19:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.