dongyou2635 2015-05-24 05:19
浏览 72

在Facebook上分享一个字符串或部分页面

I want to share a part of a page with Facebook ... this should be easy keeping in mind the scale of Facebook and the research that has been put into it. I have below loop which is fetching data from a $wpdb->select query and at the end of the loop I want a Facebook button but on click only that particular row of my MySQL table should be shared on Facebook. I know about https://developers.facebook.com/docs/plugins/share-button to get the Facebook share code but how can I use this to share only the current value of my loop. Thanks any idea !! Below is my query and foreach loop ... I am not getting hold of it how this can be done.

PHP Code

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');
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示