The concept may or may not seem interesting, but my goal was to dig deeper into WordPress to understand some of the inner workings. Thanks to tons of great web sites where people share their knowledge (most notably John Faulds code example here), and WordPress's own outstanding documentation, it was easy to develop some simple code to perform the function.
First off, let me explain my approach. It was to create all the pages in WordPress first programmatically, placing an identifier into the content section. My goal would be to read this content section later, be able to determine what content to get from my secondary database based on this information, and then retrieve and display my new information.
All you need to do is go into your functions.php page and introduce code like the following (note John Faulds' runSQL function copied here almost verbatim):
function dynamic_content() {
$content = get_the_content();
echo "
";
$sql = "select description from dates where date = '" . $content . "'";
$results = runSQL($sql);
//echo $sql;
while ($row = mysql_fetch_array($results)) {
echo $row[0];
echo "
";
}
}
function runSQL($rsql) {
$rootpasswd='
$user='
$db='
$dbcnx = @mysql_connect('localhost',$user,$rootpasswd,true);
if (!$dbcnx) {
echo '
Unable to connect to the database server at this time.
';
exit();
}
mysql_select_db($db, $dbcnx);
$result = mysql_query($rsql) or die ('test');
return $result;
mysql_close($connect);
}
This requires some explanation first. You will notice in your loop template pages that there are regular calls to "the_content". This function actually outputs content--and since my goal was to read this and replace it, the_content() is not acceptable.