我想与Facebook分享一个页面的一部分...这应该很容易记住Facebook的规模和已经投入的研究。我有以下循环,它从$ wpdb->选择查询中获取数据,并且在循环结束时我想要一个Facebook按钮,但是在点击时我的MySQL表的特定行应该在Facebook上共享。我知道https://developers.facebook.com/docs/plugins/share-button获取Facebook共享代码,但我如何使用它来共享我的循环的当前值。谢谢任何想法!!下面是我的查询和foreach循环...我没有掌握它如何做到这一点。
PHP代码
global $wpdb;
$sqll = "SELECT articles.aid, articles.username, articles.competition, articles.path, articles.category, articles.title, SUBSTR(articles.body, 1, 512) As articlebody, articles.body, Sum(zvotes.zvotes) AS votessum FROM articles LEFT JOIN zvotes on articles.aid=zvotes.aid WHERE articles.category = '$cat' && articles.competition = '$comp' GROUP BY articles.aid, articles.username, articles.competition, articles.path, articles.category, articles.title ORDER BY articles.aid DESC";
$results = $wpdb->get_results($sqll) or die(mysql_error());
$response=array();
if( is_array($results) && count($results) > 0 )
$form="";
foreach( $results as $result ) {
$form.= '<form id="voteform" action="" method="post">';
$form.= "<input id='aid' name='aid' type='text' value='$result->aid'>";
$form.= "<div id='tsm'></div>".'<br>';
$form.= "<input id='category' name='category' type='hidden' value='$result->category'>";
$form.= "Title :".$result->title.'<br>';
$form.= "<div class='mg-image' style='margin-top:15px;'><img id='articlecontest' src='$result->path' width='250' height='250' ></div>" . '<br><br>';
$form.= "<input id='competition' name='competition' type='hidden' value='$result->competition'>";
$form.= "Username :".$result->username.'<br>';
$form.= "<input id='sumofvotes' name='sumofvotes' type='hidden' value='$result->votessum'>";
$form.= "<div class='myvotes'><div id='total'>"."Total Votes:".$result->votessum."</div></div>".'<br>';
$form.= "<div id='articlesummary'>".$result->articlebody."</div>";
$form.="<div id='clickme' style='color:blue; font-size:16px; font-family: Satisfy, Cursive;'>".'READ MORE'."</div>";
$form.= '<div id="articlebody">'.'This is body text'.$result->body.'</div>';
///////////////
$form.="<input class='star' id='star1' type='image' type='submit' name='star5' src='http://localhost:8080/test/wp-content/uploads/2015/05/checkmark-small-unfilled.png' value='1' style='border:0px!important;'>";
$form.="<input class='star' id='star2' type='image' type='submit' name='star5' src='http://localhost:8080/test/wp-content/uploads/2015/05/checkmark-small-unfilled.png' value='2' style='border:0px!important;'>";
$form.="<input class='star' id='star3' type='image' type='submit' name='star5' src='http://localhost:8080/test/wp-content/uploads/2015/05/checkmark-small-unfilled.png' value='3' style='border:0px!important;'>";
$form.="<input class='star' id='star4' type='image' type='submit' name='star5' src='http://localhost:8080/test/wp-content/uploads/2015/05/checkmark-small-unfilled.png' value='4' style='border:0px!important;'>";
$form.="<input class='star' class='star' id='star5' type='image' type='submit' name='star5' src='http://localhost:8080/test/wp-content/uploads/2015/05/checkmark-small-unfilled.png' value='5' style='border:0px!important;'></form>";
///////////////
}//end of foreach
$response['form']=$form;
echo json_encode($response['form']);
exit();
}
///////////////////////////////////
add_action( 'wp_ajax_star', 'star' );
add_action( 'wp_ajax_nopriv_star', 'star');