TwitterでTwitterを投稿したり、Google +で好きなFacebookを好きなときに呼び出すカスタムプラグインを作成しています。現在のポストの代わりにページにロードされた最後の変数を使用したAJAXコール
index.phpファイル内で、これをループ内に入れて、ホームページの新しい投稿ごとに呼び出されるようにします。
ここ<?php cp_social_sharing_4pts(); ?>
私のPHPの機能の一部:AJAXはそれをここに発射した後
function cp_social_sharing_js(){
if (is_user_logged_in()) {
echo '
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
<script type="text/javascript">
twttr.events.bind(\'tweet\', function(event) { cp_share_twitter_do(); });
</script>
';
}
}
add_action('wp_head','cp_social_sharing_js');
:
function cp_share_twitter_do(){ // Tweet Entry
$cp_postID = $_POST['post']; // THIS IS THE ISSUE. It's not returning the correct ID from the post I shared on.
// Do more functions here
echo json_encode($r);
die();
}
add_action('wp_ajax_cp_share_twitter_do', 'cp_share_twitter_do');
function cp_social_sharing_4pts(){
if (is_user_logged_in()) {
echo '<script type="text/javascript">
var postid = '.get_the_ID().';
function cp_share_twitter_do(){
jQuery.ajax({dataType: "json", data: {action: "cp_share_twitter_do", post: postid},
success: function(data){
if(data.success==true){
Boxy.alert(data.message);
thebox.hide();
thebox.unload();
} else { Boxy.alert(data.message); }
}
});
}
</script>
';
}
// Show Buttons
echo 'Post ID: '.get_the_ID().'<br />'; // debug
echo '<a href="https://twitter.com/share" class="twitter-share-button" data- url="'.get_permalink().'" data-text="'.get_the_title().'" data-count="horizontal" data- via="ps3blogdotnet">Tweet</a>';
}
その後、これは頭の中にロードされます
これは完全に動作しますt。問題はホームページにあります。
変数投稿IDは、各投稿の投稿IDを正しく表示します。しかし、ajax呼び出しが完了すると、現在の投稿の代わりにホームページに表示されている最後の投稿の投稿IDが常に渡されます。
を役に立てば幸いそれ。 –