Web Design Forum: auto post inclusion - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

auto post inclusion cms to static site.. Rate Topic: -----

#1 User is offline   Martin Greenwood 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 228
  • Joined: 22-June 09
  • Reputation: 5
  • Gender:Male
  • Location:Garstang
  • Experience:Advanced
  • Area of Expertise:SEO

Posted 27 February 2010 - 12:56 PM

Hey

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?
0

#2 User is offline   empek 

  • Wordpress Geek
  • PipPipPipPip
  • Group: Members
  • Posts: 774
  • Joined: 17-December 08
  • Reputation: 76
  • Gender:Male
  • Location:New York City.
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 27 February 2010 - 01:09 PM

You could use the custom home page template from Wordpress.

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

#3 User is offline   Martin Greenwood 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 228
  • Joined: 22-June 09
  • Reputation: 5
  • Gender:Male
  • Location:Garstang
  • Experience:Advanced
  • Area of Expertise:SEO

Posted 27 February 2010 - 01:30 PM

I already knew about this but I don't want the site to be solely to be wordpress, got some things in mind that limit wps functionality...

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);
}?>

0

#4 User is offline   empek 

  • Wordpress Geek
  • PipPipPipPip
  • Group: Members
  • Posts: 774
  • Joined: 17-December 08
  • Reputation: 76
  • Gender:Male
  • Location:New York City.
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 27 February 2010 - 03:17 PM

Hey Martin,

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

#5 User is online   BlueDreamer 

  • Web Guru
  • Group: Moderators
  • Posts: 5,804
  • Joined: 23-October 07
  • Reputation: 202
  • Gender:Male
  • Location:Northampton (where?)
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 28 February 2010 - 02:09 AM

You can also pull in your latest info from a feed/XML file. Would need a bit of JS/Ajax though which isn't ideal :)
0

#6 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,814
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 28 February 2010 - 08:27 PM

View PostMartin Greenwood, on 27 February 2010 - 12:56 PM, said:

Hey

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

#7 User is offline   skidz 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,047
  • Joined: 24-November 08
  • Reputation: 135
  • Gender:Male
  • Location:Derby
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 28 February 2010 - 10:52 PM

I'd just query the rss feed with PHP or jQuery. Saves straining on the database.

There's no need for any wordpress code at all
0

#8 User is offline   empek 

  • Wordpress Geek
  • PipPipPipPip
  • Group: Members
  • Posts: 774
  • Joined: 17-December 08
  • Reputation: 76
  • Gender:Male
  • Location:New York City.
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 28 February 2010 - 11:07 PM

View Postskidz, on 28 February 2010 - 10:52 PM, said:

I'd just query the rss feed with PHP or jQuery. Saves straining on the database.

There's no need for any wordpress code at all


With wordpress code, you can use any wp function instead of having to query everything the long way.
0

#9 User is offline   skidz 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,047
  • Joined: 24-November 08
  • Reputation: 135
  • Gender:Male
  • Location:Derby
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 01 March 2010 - 10:28 AM

But he doesn't want it to be part of his wordpress site? Why unnecessarily load wordpress functioNs/config etc when all he has to do is:


a) Get the RSS Feed with jQuery / php
B) mysql_query("SELECT * FROM posts")

I'd say loading wordpress is the long way
0

#10 User is offline   empek 

  • Wordpress Geek
  • PipPipPipPip
  • Group: Members
  • Posts: 774
  • Joined: 17-December 08
  • Reputation: 76
  • Gender:Male
  • Location:New York City.
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 01 March 2010 - 11:08 AM

View Postskidz, on 01 March 2010 - 10:28 AM, said:

But he doesn't want it to be part of his wordpress site? Why unnecessarily load wordpress functioNs/config etc when all he has to do is:


a) Get the RSS Feed with jQuery / php
B) mysql_query("SELECT * FROM posts")

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

#11 User is offline   skidz 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,047
  • Joined: 24-November 08
  • Reputation: 135
  • Gender:Male
  • Location:Derby
  • Experience:Advanced
  • Area of Expertise:Web Developer

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";
	}
?>

0

#12 User is offline   empek 

  • Wordpress Geek
  • PipPipPipPip
  • Group: Members
  • Posts: 774
  • Joined: 17-December 08
  • Reputation: 76
  • Gender:Male
  • Location:New York City.
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 01 March 2010 - 11:31 AM

View Postskidz, 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! :clapping:
0

#13 User is offline   skidz 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,047
  • Joined: 24-November 08
  • Reputation: 135
  • Gender:Male
  • Location:Derby
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 01 March 2010 - 11:36 AM

Dude, I'm not after point scoring. Just want to help where I can. And if someone tells me I'm wrong and backs that up. I've learnt a new lesson
0

#14 User is offline   empek 

  • Wordpress Geek
  • PipPipPipPip
  • Group: Members
  • Posts: 774
  • Joined: 17-December 08
  • Reputation: 76
  • Gender:Male
  • Location:New York City.
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 01 March 2010 - 11:37 AM

View Postskidz, on 01 March 2010 - 11:36 AM, said:

Dude, I'm not after point scoring. Just want to help where I can. And if someone tells me I'm wrong and backs that up. I've learnt a new lesson


Exactly, and I have just learned mine. That's all I'm saying! :)
0

#15 User is offline   skidz 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,047
  • Joined: 24-November 08
  • Reputation: 135
  • Gender:Male
  • Location:Derby
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 01 March 2010 - 11:38 AM

Ok mate. Sorry thought I'd got your "back up"
0

#16 User is offline   empek 

  • Wordpress Geek
  • PipPipPipPip
  • Group: Members
  • Posts: 774
  • Joined: 17-December 08
  • Reputation: 76
  • Gender:Male
  • Location:New York City.
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 01 March 2010 - 11:39 AM

View Postskidz, on 01 March 2010 - 11:38 AM, said:

Ok mate. Sorry thought I'd got your "back up"


From me!? Neeeevvverrr!!! :friends:
0

#17 User is offline   Martin Greenwood 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 228
  • Joined: 22-June 09
  • Reputation: 5
  • Gender:Male
  • Location:Garstang
  • Experience:Advanced
  • Area of Expertise:SEO

Posted 09 March 2010 - 09:33 AM

View Postempek, on 27 February 2010 - 03:17 PM, said:

Hey Martin,

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users