Welcome to WebmasterWorld Guest from 54.167.76.176

Forum Moderators: incrediBILL

Message Too Old, No Replies

Add Wordpress Latest Blogs to Static HTML site

     

Silver007A

9:11 pm on Jul 5, 2012 (gmt 0)

5+ Year Member



Hi,

I have a simple html/css website, but want to add a latest posts div/module to the home page that feeds from a Wordpress blog I have installed in a directory on the html site server.

I have Feedburner running the blof feed to the home page at the moment, but I don't think it is the best option for the seo which is why I have inlcuded the blog in the first place.

Most other options seem to be adding some php, but then it seems I would have to change my html page to a php page, which also wouldn't be good for seo.

Can anyone help with a solution for some virtual popcorn :-)

Thanks

Silver007A

7:38 am on Jul 6, 2012 (gmt 0)

5+ Year Member



I've searched all over this site and online and still can't find a solution for this. I'm sure this is something that other people have asked for.

rocknbil

4:40 pm on Jul 6, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You can include any of the wordpress methods in any "foreign" page if you include wp-load.php.

<body>
<?php include ($_SERVER['DOCUMENT_ROOT'] . "/blog/wp-load.php"); ?>

then anywhere you want the posts,

<?php
query_posts('category_name=videos&orderby=date&order=desc&showposts=3');
while (have_posts()) {
the_post();
echo get_the_content(); // a YouTube embed code, for example
}
?>


Have a look at the documentation for query_posts() on wordpress.org to get it to do what you want.

For a truly static html/htm page, you might have to use an iframe or an SSI directive to get to this point, or parse this file as PHP, but seems like the latter is a lot of overhead, an SSI directive might work better.

londrum

5:11 pm on Jul 6, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



ive recently discovered a big problem in doing that. it does works great, but my memory use tripled on every page that i included those wordpress functions. it doesn't just load up the functions that you need to display the post... it seems to load up the whole of wordpress too (which makes sense i suppose, but it's much more than you actually need) -- and that's alongside whatever you would normal load up for your hompage.
and you will be amazed at how many database calls wordpress uses just to display one post outside of the blog

so i ended up doing just one call to the database to find the post, and doing it that way

SELECT wp_posts.ID, wp_posts.post_date_gmt, wp_posts.post_title, wp_posts.post_excerpt, wp_posts.post_status, wp_posts.post_type, wp_postmeta.meta_value

FROM wp_posts

INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)

INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)

WHERE 1=1

AND wp_posts.post_type = 'post'

AND wp_posts.post_status = 'publish'

AND wp_posts.post_date_gmt <= '".date('Y-m-d')." 00:00:01'

GROUP BY wp_posts.ID

ORDER BY wp_posts.post_date_gmt asc

LIMIT 1

rocknbil

3:21 am on Jul 7, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



That's all absolutely true. I've never even liked Wordpress, but at some point you decide whether to make a living and go with the flow or starve on principle. :-\

Silver007A

3:23 pm on Jul 7, 2012 (gmt 0)

5+ Year Member



Hi Londrum,

Would I still need to change my html page to php for your code to work? Also, can I use it exactly liek you have pasted into the post or would I need to change anything?

Thanks

tedster

5:16 pm on Jul 7, 2012 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



On an Apache server, you can parse HTML files as PHP [webmasterworld.com].

londrum

5:26 pm on Jul 7, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Would I still need to change my html page to php for your code to work? Also, can I use it exactly liek you have pasted into the post or would I need to change anything?

it depends what you need it to do. that code will choose the last post from yesterday, but you can fiddle with the
date('Y-m-d')." 00:00:01
bit.

if you want to choose the last post from a particular category instead, then i've got the code for that. or if you want to choose the last post with a particular custom_field, i've got the code for that

(it wont print anything out as posted though, obviously. it just grabs it. you need some extra stuff to print it out)

Silver007A

5:36 pm on Jul 7, 2012 (gmt 0)

5+ Year Member



I'm just looking for it to show the 4 latest posts. Title and 300 cahracter description or just Title would be good either way.


Would I still need to change my html page to php for your code to work?

londrum

9:06 am on Jul 8, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



something like this should work alright. it shows 4 latest posts, with title and excerpt. you dont necessarily have to change the .html to .php, but like tedster says, you will need to parse it as php. its probably easier just to change it to php

<?php


// connect to the database here, and then...


$query = "SELECT wp_posts.ID, wp_posts.post_date_gmt, wp_posts.post_title, wp_posts.post_excerpt, wp_posts.post_status, wp_posts.post_type, wp_postmeta.meta_value

FROM wp_posts

INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)

INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)

WHERE 1=1

AND wp_posts.post_type = 'post'

AND wp_posts.post_status = 'publish'

AND wp_posts.post_date_gmt <= '".date('Y-m-d')." 00:00:01'

GROUP BY wp_posts.ID

ORDER BY wp_posts.post_date_gmt asc

LIMIT 4";


$returns = mysql_query($query);


while ($result = mysql_fetch_row($returns)) {


echo '<h2>'.$result[2].'</h2>';

echo '<p>'.$result[3].'</p>';


}


?>
 

Featured Threads

Hot Threads This Week

Hot Threads This Month