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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,992
  • Total Topics: 21,323
  • Online today: 557
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 385
  • Total: 385

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 :)

blaze416

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?

joh87swe

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?

yameth

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.

Zetan

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...

yameth

Thanks Zetan. I will keep breathing in the meantime then. :) (Hopefully... )

This website is proudly hosted on Crocweb Cloud Website Hosting.