WordpressHere is the scenario:

You have a WordPress blog in a subfolder on your website. The main website might be static html or even php pages and you want to display your WordPress blog posts on the other ‘main website’ pages.

How do you do that?

Well I shall enlighten thee! Firstly I assume that you have your blog site in a subfolder (my subfolder is cms – so change this to your folder name), secondly if your other pages are html that is to say they are named ‘index.html’ you will have to rename them to ‘index.php’ etc. Now this will upset your links so I would do it in Dreamweaver so it automatically updates all your links.

After renaming all your files you can now start the coding, put the following code at the top (I mean the top! Before any html or anything) of each page that is to display the recent posts:

Note: change ‘cms’ to your folder name containing your wordpress blog. To control how many recent posts are displayed change the ’showposts=5′ line to however many you want (leave it like this and it will display 5….obviously)

OK all good so far! Now we need the code that will display the posts, place this somewhere in your page:





Now this will simply list your post titles, which are linked to the relative post. There are other options when listing them, you may want to list the excerpt and a read more link etc. If so the code will look like this:


Read more...

You can also pull in the your WordPress pages instead of the recent posts, simply use this code:

Replace this line

query_posts('showposts=5');

with

query_posts('page_id=7');

or

query_posts('pagename=about');

Pretty sweet – I recently used it on www.honeybeekeeping.co.uk

0

4 Responses to “Display your WordPress posts on other pages”

  1. July 20, 2009 at 10:59 am

    This is a great code! I’ve been looking everywhere for something like it.

    Thank you!

  2. Neil July 23, 2009 at 8:27 pm

    No problem David, feel free to post the web address where you used it so we can have a look!!

  3. August 13, 2009 at 5:04 am

    Thank you so much. This is exactly what I’ve been looking for. If you click my name, you will get sent to the site I am using it for.

    One question: do you know a way to include the full text for the 5 most recent links? I have it set to “excerpts” right now, but I hope to have the full text for the 5 most recent blog entries.

    Regardless, thank you so much!

  4. Neil August 13, 2009 at 7:54 pm

    Hi Andrew,

    Yes there is definitely a way to do what you ask but Im wondering why you need it? I will look into it if i can get a bit of spare time.

    Ive had a look at your site and Im unsure why you have the blog.php. Why dont you just theme the WordPress blog in your /blog/ folder to look like your html site? And get rid of the blog.php file.

    If you want me to I can theme it for you (make it look just like your html site), if you supply me all the images etc you have used in the html site I can probably do it in a day (£200).

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Switch to our mobile site

© 2012 Effutio - All Rights Reserved

Perth Web Design - Free Web Host