TinyPortal

Development => Block Codes => Topic started by: dkaye315 on April 19, 2006, 12:59:30 PM

Title: Wordpress Blog Entries extract (php) - iframe
Post by: dkaye315 on April 19, 2006, 12:59:30 PM
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]
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: Crip on April 19, 2006, 02:17:21 PM
Excellent Kaye -
(thanks a lot for this bit) - :)
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: dkaye315 on April 19, 2006, 06:23:31 PM
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>
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: IchBin on April 19, 2006, 07:32:19 PM
Wow... fantastic Kaye! I hope you stick around with your PHP skills. :)
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: Crip on April 19, 2006, 07:37:08 PM
Kaye is into ColdFusion too. ;)

PS. and formerly a Tennessean.  :up: :up:
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: dkaye315 on April 19, 2006, 07:45:40 PM
^ 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.
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: Crip on April 19, 2006, 08:02:11 PM
I'm sure I'd like CF too if I could $$ afford it ..
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: dkaye315 on April 19, 2006, 08:22:51 PM
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.
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: Crip on April 19, 2006, 08:27:01 PM
I have two servers/host, one supports CF and the other one doesn't - the one that does is: ( www.mediatemple.net )
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: deadpoeticstar on May 01, 2006, 12:47:57 AM
Just need to figure out how to do this for my Serendipity blog :)
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: blaze416 on November 04, 2007, 05:51:02 PM
is there anyway for this to just show the title of the blog entries for like the last 5.  I'm using SMFBlog now and want to move my blog to wordpress but i found on here a coding for it to show the titles of the blog on a php block.  Is there anyway to make this just show the titles?
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: joh87swe on November 26, 2007, 01:05:14 AM
I use WordPress MU with my site. This result in several database wp_posts. User one has wp_1_posts, user 2 has wp_2_posts and so on... .
I don't think this code will work, anyone has any adea?
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: yameth on March 12, 2009, 09:51:22 AM
This is an excellent idea and script!
Is it possible to show the summaries of the blog entries instead of the full stories?
In a busy news site showing the stories one after another creates a long scrolling page.
I know the thread hasn't been active for a while but... it is a very useful idea. Thanks in advance.
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: Zetan on March 12, 2009, 09:56:51 AM
Quote from: yameth on March 12, 2009, 09:51:22 AM
This is an excellent idea and script!
Is it possible to show the summaries of the blog entries instead of the full stories?
In a busy news site showing the stories one after another creates a long scrolling page.
I know the thread hasn't been active for a while but... it is a very useful idea. Thanks in advance.

Kaye hasn't been active here since: August 14, 2006, nearly three years. I wouldn't hold your breath for a reply. Whether anybody else is able or willing to help...
Title: Re: Wordpress Blog Entries extract (php) - iframe
Post by: yameth on March 12, 2009, 11:08:31 AM
Thanks Zetan. I will keep breathing in the meantime then. :) (Hopefully... )