Share a string or part of page on 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');


Source: wordpress

Leave a Reply