0

我想在 facebook 上发布 wordpress 帖子。我使用了 facebook 的 javascript SDK 并使用 save_post 钩子来获取帖子的标题和内容。但是,问题是 save_post 在 php 中,我必须在 javascript 中使用变量,但我无法做到。我什至怀疑我所做的是否正确。

这是我的js代码

function streamPublish(name, description, hrefTitle, hrefLink, userPrompt)
{
            showLoader(true);
            FB.ui(
            {
                method: 'stream.publish',
                message: '',
                attachment: {
                    name: name,
                    caption: '',
                    description: (description),
                    href: hrefLink
                },
                action_links: [
                    { text: hrefTitle, href: hrefLink }
                ],
                user_prompt_message: userPrompt
            },
            function(response) {
                showLoader(false);
            });

        }
        function showStream(){
            FB.api('/me', function(response) {

            var fbpost = document.getElementById('posttofb').val();
            alert(fbpost);

            streamPublish(response.name, 'title', 'hrefTitle', 'http://thinkdiff.net', "Share thinkdiff.net");

            });
        }

和我的 php 代码

add_action('save_post','save_post_callback');
function save_post_callback($post_id)
{
global $post; 
if ($post->post_type != 'post')
{
    return;
}
else
{
echo"122222222222222";
?>

<div id="posttofb">
<?php
$title=$post->post_title;
?>
</div> 

<?php
echo $post->post_content;
//echo $post->the_title();
}
}

?>
4

1 回答 1

0

您将在 id posttofb 写入后执行您的 javascript。

尝试类似:

<div id="posttofb">
<?php
$title=$post->post_title;
?>
</div> 
<script>
$(function() { //document.Ready
showStream();
});
</script>

或者仅在这种情况下(将您的 showStream 更改为 showStream(title)):

<script>
$(function() { //document.Ready
showStream(<?=$post->post_title?>);
});
</script>
于 2013-04-23T12:11:23.993 回答