A simple WordPress plugin to show data from an external table

No GoodNeed ImprovementOKGoodExcellent (No Ratings Yet)
Loading ... Loading ...

This is my first WordPress plugin, very simple, it takes information from a table called “grants” and shows grant infomation as a post’s content. See http://www.researchgrantdatabase.com for action.

<?php
/*
Plugin Name: Grant Info
Plugin URI: http://www.researchgrantdatabase.com/
Description: Show grant information
Author: Paul Shaw
Version: 0.1
Author URI: http://www.researchgrantdatabase.com/
*/
?>
<?php
/* Copyright InnoVita Inc, innovita (at) gmail dot com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

function grant_info() {
global $wpdb, $post;
$postID = $post->ID;
$grants = $wpdb->get_results(”select grant_id, post_id, agency, irg,
year, grant_type, application_type, award_date,
project_start, project_end, amount, pi_name, pi_title, pi_firstname,
pi_lastname, pi_middlename, pi_email, department, organization, org_company,
state_country, project_title, keywords, abstract
from grants where post_id= $postID”);

foreach ($grants as $grant)
{
$dept= $grant-> department;
if (strlen ($dept)>0)
{
$dept = $dept.”, “;
}

$pi_title= $grant-> pi_title;
if (strlen ($pi_title)>0)
{
$pi_title =”, “. $pi_title;
}
$content= “<div class=\”grantee\”>”. $grant-> pi_name . $pi_title .”</div><br />”.
“<div class=\”institution\”>”. $dept. $grant-> organization .”</div><br />” .
“<div class=\”grantfrom\”>Grant <font class=\”grantid\”>”.
$grant-> grant_id.”</font> from “. $grant->agency.”, <font class=\”irg\”>IRG: “. $grant->irg.”</font></div><br />”.
“<div class=\”projinfo\”>”;
if (strlen ($grant-> project_start)>0)
{
$content .= “Project start date: “. $grant-> project_start ;
}
if (strlen ($grant-> project_end)>0)
{
$content .= “<br />Project end date: ” . $grant-> project_end ;
}

$content .=”</div><br />”;
print_r($content);

echo “<div class=\”abstract\”>”;
echo $grant->abstract;
echo “</div><br />”;
// if (strlen($grant->keywords)>0)
// {
// echo “<font class=\”keyword_title\”> Keywords:</font><div class=\”keywords\”>”;
// echo $grant->keywords;
// echo “</div><br />”;
// }
}

}

?>

Popularity: 1%

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word