TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

April 18, 2024, 06:24:46 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,164
  • Total Topics: 21,219
  • Online today: 203
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 134
  • Total: 135
  • @rjen

Wordpress Blog Entries extract (php) - iframe

Started by dkaye315, April 19, 2006, 12:59:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dkaye315

Not wanting to fully integrate WP with SMF, and only wanting to include current blog entries on the front page, wrote a simple php query to the db, returning the 3 most recent entries.  Then set up a html block for the frontpage - however, could be used anywhere within the TP structure.

Here's the php code:

<html>
<head>
<title>From the Blog</title>
<link rel="stylesheet" type="text/css" href="yoursite/forum/Themes/yourtheme/style.css">
<style>
body{
background: #ffffff;
}
</style>
</head>
<body bgcolor="#e4e1e1">
<table border="0" valign="top" bgcolor="#ffffff" cellpadding="5">
<?php
 
/* This grabs posts from the blog */
$db mysql_connect("localhost""root""password1"); // password if needed
mysql_select_db("php3"$db); // change php3 to your database
$sql 'SELECT * '
        
' FROM `wp_posts` '
        
' WHERE `post_status` = \'publish\'' // grab only published posts
        
' ORDER BY post_date DESC LIMIT 3'// grab the latest 3 posts in descending order
$result mysql_query($sql);
while (
$row mysql_fetch_array($result)) {
print(
"<tr><td><hr width=\"75\" align=\"left\"><br>");
printf("<b><font size=\"3\" color=\"#2c2c27\">%s</font></b>\n",
$row["post_title"]);
printf("<br><font size=\"1\" color=\"#333333\">Posted: %s</font><br><br>\n",
$row["post_date"]);
printf("<font size=\"2\">%s</font></td></tr>\n",
$row["post_content"]);
}
?>

</table>
</body>
</html>


Save the above code as a php file within the forum folder, and replace the necessary variables to match those of your db and template stylesheet.

Then create a html block using the following code:

<IFRAME marginWidth=0 marginHeight=0 src="blog_query.php" frameBorder=0 width="100%" height=600 ></IFRAME>

I set mine to scroll as there was a lot of text.  Adjustments can be made to suit individual tastes/needs.

Hope this is helpful to someone else.  As well, any improvements always appreciated.

[edit: forgot to include the link to view:  http://dkaye.com/ecafe/index.php]

Crip

Excellent Kaye -
(thanks a lot for this bit) - :)
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



dkaye315

#2
Improved the previous code to include a 'die' tag, 'error' tag, and 'close' tag.  Following is the revision:


<html>
<head>
<title>From the Blog</title>
<link rel="stylesheet" type="text/css" href="http://YOURSITE.COM/FORUM/Themes/YOUR_THEME/style.css">
<style>
body{
background: #ffffff;
}
</style>
</head>
<body bgcolor="#e4e1e1">
<?php  
$server 
"localhost";    // change to your servername
$username "YOUR_USERNAME";   // change to your username
$password "YOUR_PASSWORD";  // change to your password

$link mysql_connect ($server$username$password
or die (
"Could not connect"); 
?>


<?php
/* Connects to the MySQL server */ 
$link = @mysql_connect ($server$username$password
or die (
mysql_error());

/* Defines the Active Database for the Connection */ 

if (!@mysql_select_db("YOUR_DATABASE"$link)) {       // change to your database
     
echo "<p>There has been an error. This is the error message:</p>"
     echo 
"<p><strong>" mysql_error() . "</strong></p>"
     echo 
"Please Contact the Forum Administrator with the details"
}

 
/* Grabs posts from the blog */
$sql 'SELECT * '
        
' FROM `wp_posts` '                           // change to your table name if different
        
' WHERE `post_status` = \'publish\''
        
' ORDER BY post_date DESC LIMIT 3'
$result mysql_query($sql);
?>


<!-- /* View posts from the blog */ -->
<table border="0" valign="top" bgcolor="#ffffff" cellpadding="5">
<?
while ($row = mysql_fetch_array($result)) {
print("<tr><td><hr width=\"75\" align=\"left\"><br>");
printf("<b><font size=\"3\" color=\"#2c2c27\">%s</font></b>\n",
$row["post_title"]);
printf("<br><font size=\"1\" color=\"#333333\">Posted: %s</font><br><br>\n",
$row["post_date"]);
printf("<font size=\"2\">%s</font></td></tr>\n",
$row["post_content"]);
}
?>
</table>

<? 
mysql_close ($link);
?>
</body>
</html>


NOTE: Be sure to change the variables where commented above.

The iframe remains the same - rename the query file to whatever suits your needs:
<IFRAME marginWidth=0 marginHeight=0 src="blog_query.php" frameBorder=0 width="100%" height=600 ></IFRAME>

IchBin

Wow... fantastic Kaye! I hope you stick around with your PHP skills. :)

Crip

#4
Kaye is into ColdFusion too. ;)

PS. and formerly a Tennessean.  :up: :up:
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



dkaye315

^ and ^^ - Thank you kindly.   :)  This type of 'tinkering' helps me as I prepare to convert a massive database suite from MS Access (VB,SQL) to a secure web-based CF/SQL/PHP.  I like the security CF affords - especially where sensitive data is a concern.

Crip

I'm sure I'd like CF too if I could $$ afford it ..
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



dkaye315

Fortunately, it's one of the app's available through my host.  Use DreamWeaver for site development which has CF design capability.  From a page design standpoint, very easy to convert standard html to CF -  basic change was the file extension.

Crip

I have two servers/host, one supports CF and the other one doesn't - the one that does is: ( www.mediatemple.net )
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



deadpoeticstar

Just need to figure out how to do this for my Serendipity blog :)