auto post inclusion cms to static site..
#1
Posted 27 February 2010 - 12:56 PM
I'm re-coding my website and I wanted to know if there was some way of pulling in my most recent posts from my wordpress blog.
There will be a static site @ domain.com and the blog in the sub-directory /blog....does anyone know how to do this?
#2
Posted 27 February 2010 - 01:09 PM
A loose step-by-step:
- Create a new .php file with the following code at the top:
<?php /* Template Name: Main Page */ ?>
- Paste in the code for the homepage
- In place where you want to show the latest blog posts add:
<?php query_posts('showposts=5'); ?> <ul> <?php while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile;?> </ul> - Save file and log into Wordpress back-end
- Go to Settings > Reading and change the front page display to a static page, and select the page name you gave your file (Main Page in our example)
- Save settings, and view your site
If all goes well, you should be able to see your homepage with the 5 latest posts in a list. Once you have that set up, create a new page called Blog, and use the Default Template as the Template (in the right sidebar). Finally change your permalinks (Settings > Permalinks) by changing them to custom : /%category%/%postname%/.
Your blog homepage will now be at domain.com/blog/.
More info on Page Templates here.
Let me know if this helps, or if it causes any trouble.
#3
Posted 27 February 2010 - 01:30 PM
i came up with this but dunno if it will work....
<?php
$how_many=5; //how many posts to display
require('blog/wp-config.php'); //the path to the wp-config file of the blog I want to use
$news=$wpdb->get_results("SELECT 'ID','post_title','post_content' FROM $wpdb->posts
WHERE 'post_type'=\"post\" AND 'post_status'=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
foreach($news as $np){
printf ("<div class='normalText'>%s</div>", $np->post_content);
}?>
#4
Posted 27 February 2010 - 03:17 PM
In order to display posts on a non-wordpress static page, you need to do the following:
Make sure your homepage is a .php file and at the very top paste in:
<?php
// Include Wordpress
define('WP_USE_THEMES', false);
// Change path below to location of wp-blog-header.php on server
require('/home/username/public_html/blog/wp-blog-header.php');
// Change number below to show 1 or more post excerpts
query_posts('showposts=1');
?>
And then code a wp loop as if you were in wp anywhere you want it like so:
<ul id="latest-blog-posts"> <?php while (have_posts()): the_post(); ?> <li><a href="<?php the_permalink(); ?>" title="Read full post"><?php the_title(); ?></a><br/><small>Posted on <?php the_date(); ?></small> </li> <?php endwhile; ?> </ul>
+1 if it worked
#5
Posted 28 February 2010 - 02:09 AM
#6
Posted 28 February 2010 - 08:27 PM
Martin Greenwood, on 27 February 2010 - 12:56 PM, said:
I'm re-coding my website and I wanted to know if there was some way of pulling in my most recent posts from my wordpress blog.
There will be a static site @ domain.com and the blog in the sub-directory /blog....does anyone know how to do this?
You go down the simplest route and just query your wordpress db as you would any other db, or even parse the rss/xml feeds that wordpress creates for you.
#7
Posted 28 February 2010 - 10:52 PM
There's no need for any wordpress code at all
#9
Posted 01 March 2010 - 10:28 AM
a) Get the RSS Feed with jQuery / php
I'd say loading wordpress is the long way
#10
Posted 01 March 2010 - 11:08 AM
skidz, on 01 March 2010 - 10:28 AM, said:
a) Get the RSS Feed with jQuery / php
I'd say loading wordpress is the long way
Eh, you might be right. Can't wait to see what Martin is cooking up anyways.
#11
Posted 01 March 2010 - 11:24 AM
<?php
$aQuery = mysql_query("SELECT ID,post_title,post_content FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY past_date DESC LIMIT 5");
while($aResults = mysql_fetch_array($aQuery))
{
echo $aResults['post_title'] . "<br />\n";
}
?>
#12
Posted 01 March 2010 - 11:31 AM
skidz, on 01 March 2010 - 11:24 AM, said:
<?php
$aQuery = mysql_query("SELECT ID,post_title,post_content FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY past_date DESC LIMIT 5");
while($aResults = mysql_fetch_array($aQuery))
{
echo $aResults['post_title'] . "<br />\n";
}
?>
I suppose you've proven your point!
#13
Posted 01 March 2010 - 11:36 AM
#17
Posted 09 March 2010 - 09:33 AM
empek, on 27 February 2010 - 03:17 PM, said:
In order to display posts on a non-wordpress static page, you need to do the following:
Make sure your homepage is a .php file and at the very top paste in:
<?php
// Include Wordpress
define('WP_USE_THEMES', false);
// Change path below to location of wp-blog-header.php on server
require('/home/username/public_html/blog/wp-blog-header.php');
// Change number below to show 1 or more post excerpts
query_posts('showposts=1');
?>
And then code a wp loop as if you were in wp anywhere you want it like so:
<ul id="latest-blog-posts"> <?php while (have_posts()): the_post(); ?> <li><a href="<?php the_permalink(); ?>" title="Read full post"><?php the_title(); ?></a><br/><small>Posted on <?php the_date(); ?></small> </li> <?php endwhile; ?> </ul>
+1 if it worked
dude - you are awesome! - it worked a treat
p.s. I'm not cooking up anything special, just wanted to include the list of most recent articles on my home page to increase the click through rate to my blog
Help


















