How to add recent WordPress post exceprts on an external html page


25 of May2007

*** Update (Apr 4 08): I added a line of code that should strip out all HTML tags and formatting. So the resulting excerpt should only be text

Related Post: How to display 5 full posts…

Say you have a homepage that is not run by WordPress, and you just have your blog in the /blog/ directory or something like that. Yet you STILL want to display an excerpt from your recent post on your home page.

The solution? Use PHP and MYSQL to directly fetch the content from the WordPress database without even using WordPress.

1) Here’s the code you will want to write in BEFORE the Doctype (so the very first of your HTML):

<?php
//db parameters
$db_username = '###';
$db_password = '###';
$db_database = '###';

$blog_url = 'http://www.jamischarles.com/blog/'; //base folder for the blog

//connect to the database
mysql_connect(localhost, $db_username, $db_password);
@mysql_select_db($db_database) or die("Unable to select database");

//get data from database
$query = "Select * FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY id DESC LIMIT 1"; 

$query_result = mysql_query($query);
$num = mysql_numrows($query_result);

//close database connection
mysql_close();

//assign data to variables
$blog_date = mysql_result($query_result, 0, "post_date");
$blog_title = mysql_result($query_result, 0, "post_title");
$blog_content = mysql_result($query_result, 0, "post_content");
//$blog_permalink = mysql_result($query_result, 0, "guid"); //use this for 'p=11' format

$blog_permalink = $blog_url . mysql_result($query_result, 0, "post_name"); //combine blog url, with permalink title. Use this for title format

//format date
$blog_date = strtotime($blog_date);
$blog_date = strftime("%b %e", $blog_date);

//how many characters should be shown?
$maxchars = 135;

//strip out the html tags, such as images, etc...
$blog_content = strip_tags($blog_content);

//cut down the size of the post to 135 characters
$blog_content = substr($blog_content, 0, $maxchars);
$blog_content = $blog_content . "...";

// html page starts after ?>
?>
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
</head>

2) Find the “wp-config.php” file and the first three lines or so should contain your database name, user name, and password. Enter those in your file where I have ### for the db parameters. Just copy the names as shown in below. Do NOT CHANGE the “wp-config.php file”. WordPress will stop working if you do.

<?php
// ** MySQL settings ** //
define('DB_NAME', 'my_wordpress');    // 'my_wordpress' is the name of the database
define('DB_USER', 'my_user');     // 'my_user' is your MySQL username
define('DB_PASSWORD', 'my_password'); // 'my_password' is the password

3) Rename the file you are using to .php

4) Find a spot in your html where you want to display your date, title, and post excerpt. For example:

 
<div id="myId">< ?php echo $blog_date; ?>:

< ?php echo $blog_title; ?> 

< ?php echo $blog_content; ?>
 

<a href="<?php echo $blog_permalink; ?>">More </a>
</div>

The above code will display the following:

May 25:
Show only the titles on the Archive Pages

Thanks to www.spiritfolk.com for this one. 1) Open up /wp-content/themes/default/archive.ph…

More

Your Words


  1. No 1 by
    Orion

    Thanks, this will work perfectly for me if I can change just one part. What can I modify in this code to show the 3 most recent posts?

  2. [...] popular request I’ve decided to add another tutorial, similar to the previous one, on how to add several full blog posts on an external [...]

  3. Here you go Orion :

    How to add 5 full WordPress posts on an external html page

  4. No 4 by
    zac

    thanks.. this is what i was looking for. does this mean that anyone who looks at the source of this page will see all of the database info (username and password) ?

  5. Zac:

    The answer is no. PHP is “server side” that means all of the php is run on the server, then shows the client the result. If you view the source of my homepage you won’t see any of the PHP. That’s the beauty of PHP, it’s all run and done before the browser sees it.

  6. No 6 by
    3lie

    Just perfect!

    One more thing…. this code only works for the last post of the blog. How can i do to show the 5 last posts?
    Do i need to add something? or write a function?

  7. No 7 by
    Lynn

    This is a nifty idea. I wonder how to use it to display recent posts from TWO DIFFERENT blogs on an external home page. Right now I am calling the posts from ONE blog using php require(‘blogName1/wp-blog-header.php’). Do you think I can use this in conjunction with that to get the posts from the SECOND blog which uses a seperate database? Using php_require twice, once for each blog doesn’t work, and it looks like the direct call to the database might be useful for me if I know that it would not mess up the way I am calling posts from Blog1. Hope this makes sense. . .the client site is not live yet, so I can’t show an example.

  8. Lynn: Well, I am sure you can get the info from 2 blogs as long as the databases are part of the same site. I’ll send you a personalized file.

  9. No 9 by
    LSCanada

    Jamis, thanks a lot. It is very useful and defiantly clear solution. Exactly what I was looking for.

    But is it possible to call the content from the WordPress database that is on another site?

  10. No 10 by
    jamis

    I am not sure if this is possible for security reasons. It certainly is worth taking a look at though.

    Update (4/4/08): I believe it is possible to call the wordpress blog from another site but you need several things. 1) Obviously you need the password and login credentials. 2) You need your sever (the one hosting the remote wordpress blog) to have Remote MYSql access enabled. If you are using CPanel you can do that, and add the IP address of your server (not the remote one) as an access host.

  11. Greetings! jamis!I think, your comment to this clause very opportunely. And where a source?
    Thanks, now all became clear!

  12. No 12 by
    Jason Van Schooneveld

    I posted this question on the other thread, but I can post it here as well. I was wondering if there was anyway to get the permalinks from the blog post onto the external page as well. Also, different question…is there anyway to limit the amount of blog content that is displayed on the external page. On the site that I am building I only want a snippet of the post. Maybe the first couple lines. thanks

  13. No 13 by
    jamis

    Jason: That’s what this post shows. How to include only a snippet. As the permalink, let me look into that.

  14. No 14 by
    Jason Van Schooneveld

    I see. The reason I was confused was because I was using the “how to display 5 full post” code instead which displays full posts (obviously from the title of the post. DOH). I spliced in the maxchar variable and now it works. I look forward to hearing your thoughts on the permalink. thanks

  15. No 15 by
    Brian Christensen

    This is nice! Could you perhaps also tell us, how to query X number of post from a specific category? I am trying to build a static frontpage that query contants from 5 wordpress site – A kind of intro site, to my wordpress world.

  16. No 16 by
    jamis

    Jason: I added the permalink into the code. Now the “More” link on the bottom is a link to the permalink.

  17. Agree with Brian C – would be great to know how to do this, displaying the latest posts in X category…
    I’ve been going nuts trying to figure it out :)
    Many thanks

  18. Just to say – I figured out how to display posts only from one category; thought it might be useful to others to post it up here:

    from WHERE post_type=’post’

    to

    id=”3″

    3 being the id of the category I wanted to display

    Hope that helps :)

  19. No 19 by
    jamis

    emerald: Let me try that out and see what happens.

  20. Love the script! I have been searching for ages for this. It’s perfect!

    Jason Van Schooneveld asked how to get the link to lead to the story? Here’s how:
    <a href=”http://your.blog.address.com//”>

    If your story has the address http://www.blog.com.au/my-blog/ then the blog_name is my-blog.

    My question is how to rearrange the order? Can it be rearranged so that the NEWEST story is at the top and the oldest at the bottom? This would suit my purposes better. Ideas?

  21. No 21 by
    Jim

    HELP! My database is through Yahoo Small Buisness. When I set up my blog I was one of the 1% that had to change the DB_Host from localhost to “mysql”

    // ** MySQL settings ** //
    define(‘WP_CACHE’, true); //Added by WP-Cache Manager
    define(‘DB_NAME’, ‘xxx’); // The name of the database
    define(‘DB_USER’, ‘xxx’); // Your MySQL username
    define(‘DB_PASSWORD’, ‘xxx’); // …and password
    define(‘DB_HOST’, ‘mysql’); // 99% chance you won’t need to change this value

    In your code I see this:

    //connect to the database
    mysql_connect(localhost, $db_username, $db_password);
    @mysql_select_db($db_database) or die(“Unable to select database”);

    Should I change the localhost to something else? I tried changing it to “mysql” didnt work.

    Any ideas?

  22. No 22 by
    jamis

    Jim: Not quite sure. Have you tried entering the ip address of your server instead of “localhost”?

  23. No 23 by
    jamis

    Emerald: I tried what you suggested, but it didn’t quite work.

  24. No 24 by
    jamis

    Adam: Find the query that states: $query = “Select * FROM wp_posts WHERE post_type=’post’ AND post_status=’publish’ ORDER BY id DESC LIMIT 1″;

    Then change the “ORDER BY id” to “ORDER BY post_date”. You might have to change “DESC” to “ASC”. Change the LIMIT number if you want to display more posts. Let me know if that works for you.

  25. I just found this code, and would love to use it, but I’m having trouble with some formatting stuff.

    1) This doesn’t seem to bring in breaks that were in the initial post, so “Hello…World.” simply appears as “Hello…World.” Is there any way to fix that?
    2) For some reason it’s adding a ton of question marks to my posts, in seemingly random places. Why would it do that?
    3) Finally…is there any way to use this to change the date format? I would love to show the post date using the PHP Date Format of “n.j.y” but I’m not sure what this %b and % e are?

    If there are ways to fix some of these things, I would love to use this code. For examples of the problems I’m having, see the front page of cutaia.net.

    Thanks!

  26. Sorry to waste your time, but I’m thinking I may use a variation of this advice: http://wordpress.org/support/topic/102385

  27. No 27 by
    Matt

    I’m confused on step (3) where you say ‘rename the file as .php’

    This sounds exactly like what I’m looking for, but are you saying my page XX.shtml now has to be XX.php? Since I my visitors have XX.shtml bookmarked, it’s imperative I don’t change that filename. If you could clarify that a bit, it would be a big help for this novice code writer! Thanks.

  28. No 28 by
    jamis

    Matt: In order to run the php commands that fetch the data from the database, the file must in .php. What you could do is write a php or javascript forward that automatically send them on to the .php file.

  29. No 29 by
    jamis

    Cutaia: Let me know how that goes.

  30. No 30 by
    jamis

    Cutaia: This page http://us.php.net/manual/en/function.strftime.php explains what the %b and %e are.

  31. Jamis: I got it working using the above example as flukily the id of the category and of the individual post where the same (3). As soon as I updated the blog, it broke.

    But! I have fixed it for sure now, so, if you want to display the latest post in a particular *category* change the bit –

    FROM wp_posts WHERE post_type=’post’ AND post_status=’publish’ ORDER BY id DESC LIMIT

    to

    FROM wp_posts WHERE post_type=’post’ AND post_category=’[the name of your category]‘ AND post_status=’publish’ ORDER BY post_date desc LIMIT

    Hope this helps :)

  32. No 32 by
    steve

    For some reason I can’t get the permalink code to work except for the first article. Any ideas why?

  33. No 33 by
    steve

    I found the mistake. Here’s full code calling five listings with maxcharacters and permalinks.

    <?php

    //start a loop that starts $i at 0, and make increase until it’s at the number of rows

    for($i=0; $i

    <a href=”">

    <a href=”">More >>

    :

  34. No 34 by
    Andy

    Hey there

    Love this idea and works great but I have images in my posts that I want to show up but for some reason they won’t show using this code.

    I am running everything on a local server and in the img tag I am getting this:

    <img src=”http://loc…

    and won’t show the image.

    Any ideas?

  35. No 35 by
    Michael Garfinkel

    Anyway to change it from posts to pages.

  36. No 36 by
    Linda

    Thanks for a great script! Is there any way though to make the script NOT count URL’s as chars? Cause now I have to edit my posts all the time cause links mess upp the excerpt. Also, is there a way for the script to exclude pictures?

  37. Wow, that is a lot of work. Did you know the ability to do what you want has been part of WordPress for years, and it can be done in two lines? See the Integrating WordPress subsection of the Creating a Static Front Page entry in the WP wiki. Most of that page is outdated, as noted at the top, but this subsection is still very useful and does exactly what you want.

    Basically, put this at the top of your external page:

    After that you can use any WordPress functions you want, including setting up a loop the same way you would in any other WP template file. Use get_header() and get_footer() to pull in your WP theme as well.

  38. No 38 by
    Pieter

    And there’s still the problem with the line breaks/formatting…

  39. No 39 by
    jamis

    Andy, and Linda: I’ll have to adjust the script so it doesn’t cut off in the middle of a tag. That includes images. I’ll look into that.

  40. No 40 by
    jamis

    Kenn: I understand that. What you are describing requires the front page to be in the WordPress folder. I don’t want that. I want a page that has nothing to do with WordPress be able to display WordPress posts.

  41. Nope, it doesn’t have to be in the WP application directory; the static page simply needs filesystem access to it. It can be used in any PHP file, anywhere on your site. For example, I install WP in a subdirectory but use this method at the top-level, which is one level above where WP lives. All you have to do is adjust the path in the require() line appropriately for your use.

  42. No 42 by
    jamis

    LSCanada: I believe it is possible to call the wordpress blog from another site but you need several things. 1) Obviously you need the password and login credentials. 2) You need your sever (the one hosting the remote wordpress blog) to have Remote MYSql access enabled. If you are using CPanel you can do that, and add the IP address of your server (not the remote one) as an access host.

  43. No 43 by
    jamis

    Kenn: I can see what you’re saying. I just gave it a try. That does seem useful. I’m not sure however, if it would be less work. The benefit of doing it the way you’re suggesting is that you can use all of the WordPress functions and themes defined therein.

    I wanted to keep the themes separate and not use any of my WordPress styles on my static page. The tutorial on that you showed me doesn’t show how to do anything except for get the permalinks. Obviously it could be figured out without much work, but is that less work than just copying and pasting what I have above?

    Let me know what you think. Thanks for the info.

  44. You can avoid using the WP theme by simply not calling get_header() and get_footer(), thus enabling you to use the WP framework for displaying post content while maintaining a completely different look, if you prefer.

    It is much less work because the method posted here requires a lot of duplicated effort. If your database login changes, you have to update it both here and in WP. If the WP database schema changes, you have to update your code here instead of just letting WP handle it for you.

    The sample code there is really poor because it has you writing your own SQL and such. I don’t know if that’s outdated or what but there’s a much easier way. Once you have wp-blog-header.php included you can use any WP functions, which includes constructing new loops using query_posts() and whatever parameters you want in order to pull in exactly the content you want, whether it’s a single post, multiple posts, full text, permalinks, whatever.

  45. By “poor sample code” I was referring to that in the WP codex, not yours. Sorry.

  46. No 46 by
    jamis

    Andy and Linda: I added one line of code, so it’ll now strip out all of the tags from the excerpt. That should fix problems of having half of an image pulled in or half of a link. Let me know if it works.

  47. No 47 by
    jamis

    Kenn: That’s alright :) . Thanks for the info. I’ll try and rewrite it using the WP functions when I have a second. Off the top of your head, you don’t know a function for displaying the excerpts short of using a plugin, do you?

  48. You mean aside from the_excerpt()?

  49. No 49 by
    jamis

    Kenn: Perfect, thanks.

  50. This is perfect! I used the “How to add 5 full WordPress posts on an external html page” tutorial and it let me do exactly what I needed to, with a bit of tweaking on the Drupal code, to integrate my WordPress blog into my Drupal website. Thank you so much for the work at figuring this stuff out. :-D

    I’m still working to get the site organized just right, but after months of trying to get it to work, the melding of the blog into the site is now seamless. And it only took a few hours to get it done. Thank you!

    And for those who might prefer full date like I do – I changed the date code of “%b %e” to “%B %e %Y” so I get a date of April 19 2008 instead of Apr 19 (%b = first few letters of month, %B = full month name, %y = 2 digit year 08, %Y = full year 2008)

    Thanks again for the hard work Jamis, you rock!

  51. No 51 by
    Jim

    Help! Bit off-topic, but would you know how to return the date (or time since) of the last post on a non-external page – ie, a wordpress homepage? I’m really stuck….

  52. Hi Jamis, thank you SO MUCH for this fabulous code. I read through all the comments looking for a way to pull from a specific category, as I have yet to get it wor correctly. As for the wordpress available inclusion code vs yours… yours works well for me because I am pulling in blog excerpts on a site that is different than that of the blog and does not have relative file access.. and the host does not allow url file access.. yet i can access mysql. so please dont change it too much, there is a purpose and a use for both methods :D

    thank you again!

  53. No 53 by
    Erica

    First, thank you so much!

    I’m having an issue with formatting once the post is imported. Line breaks are disregarded…

    I commented out the code to “remove tags” from your piece, and that helped by bringing back the bold formatting on the text, but I’m still not seeing line breaks?

    I’d be happy to provide you with the link, if you have the time to look at it (it’s on a testing server that I’d rather not give the link out publicly yet!) Thank you again!!

  54. No 54 by
    Daan

    Absolutely terrific programming!

    Please could you let me know if there is any way to show a random post from the database?

    It would make my day :)

  55. Hi great work guys – is there a way of having the 3 most recent posts as excerpts? (not the full versions)

    Cheers

  56. No 56 by
    Al

    Script works great. Is there a way to trim at the end of a work instead of at the and of 135 characters. I am left with it trimming a word in the middle. Any help would be greatly appreciated.

  57. wow im really confused, forgive me am no good to this thing, but should i put the php script on a separate file and access it from another html file or everything will be on same page? please help me coz what was displaying is this:

    ?>
    :

    ”>More

    i saved my html as test.html and renamed it test.php but how can i open this in a browser? it only show the code! thanks

  58. No 58 by
    Matt

    Hi, I’m not sure if anyone is still watching this post to respond, but I am getting the same error as cutaia a few posts up. There are randomly inserted question marks throughout my posts. Anyway to fix this?

  59. No 59 by
    Al

    I was trying to modify this to only post the last 5 from a specific category. The previous solutions mentioned here did not work for me as the categories are kept in a separate table not in wp_posts. They are kept in wp_categories by cat_ID or cat_name. The post_category in the wp_post table doesn’t seem to house any information. Any help would be greatly appreciated. Still running wp 2.2.

  60. No 60 by
    Dru

    Hi.

    First off, amazing tutorial and thanks so much to the author!

    I found an error with the html portion of code preventing the permalink link to the blog post to work.

    Remove the quote marks from the following code for the permalink to actually link. Leaving the quote marks in there introduces an additional url string.

    <a href=””>More

    This would result in my case as http://www.travelers411.com/“http://www.travelers411.com/blog”

    Removing the quotes results in a proper url link to:
    http://www.tavelers411.com/blog

    -Dru

  61. I would also like it to pull X amount of posts from the Y category

    please help!

  62. [...] Just Good Clean Fun » Blog Archive » How to add recent WordPress post exceprts on an external html… Say you have a homepage that is not run by WordPress, and you just have your blog in the /blog/ directory or something like that. Yet you STILL want to display an excerpt from your recent post on your home page. (tags: wordpress php mysql) [...]

  63. Jamis, Kenn might be right and it already exists in WordPress, but I couldn’t figure it out based on the instructions they gave. Yours worked FIRST TRY. This is amazing stuff and thanks so much. Also, Dru, thank YOU. The only problem I had was the permalink!

  64. No 64 by
    Murtaza

    I tried this tutorial, but I want to display 5 posts so I updated the following code

    $query = “Select * FROM wp_posts WHERE post_type=’post’ AND post_status=’publish’ ORDER BY id DESC LIMIT 1″;

    to
    $query = “Select * FROM wp_posts WHERE post_type=’post’ AND post_status=’publish’ ORDER BY id DESC LIMIT 5″;

    but i dont know why its not working please help me out.

  65. How can I chnage the query so that it selects all posts from all categories except one specific one?

    Thanks.

  66. No 66 by
    Cloud

    Hello,

    First of all, great script, thank you very much for sharing it. I have edited it slightly for my purposes (removing the portion that strips html) and I am trying to use this script to pull an embedded video from a wordpress entry and place it in a “featured videos” box on my webpage. I am able to pull formatted text and images, but when I try to pull a video the result is a blank page.

    Any help would be greatly appreciated!

  67. Well i didn’t get it. how to use it. My website is in PHP. so it will work in PHP.

    And i am sorry for that my English is not good. So i have a problem to understand that how i can manage it on website.

  68. No 68 by
    jamis

    Martin said:

    How can I chnage the query so that it selects all posts from all categories except one specific one?

    @Martin: I’m not sure, that’s a little more tricky.

  69. Hey Jamis,

    From an older reply you did on October 15th, 2007 at 10:36 am
    “Lynn: Well, I am sure you can get the info from 2 blogs as long as the databases are part of the same site. I’ll send you a personalized file.”
    ___________________________________________________

    I would like to do the same. If you wouldn’t mind, could you send me that personalized file as well. I have two blogs I would like to have both just the resent post pulled to the home page of the site. This would be really great if I can get this to work. But I have to say the current code is incredible.

    Thanks in advance.

  70. No 70 by
    Kenny

    Wow, exactly what I was looking for! Thanks.

    But like Darrel (September 8th, 2008 at 4:11 pm), I too, wanted to pull X amount of posts from the Y category.

    It seems that the new WordPress table structure is a bit different, and post_category doesn’t work any more.

    So a good buddy of mine sent me the following query which works like a charm. Just use this with the rest of Jamis’s code:

    $query = “SELECT distinct ID, post_title, post_date, guid, post_content, post_name FROM wp_posts, wp_terms, wp_term_relationships WHERE wp_posts.id = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_terms.term_id AND post_type=’post’ AND post_status=’publish’ AND wp_terms.slug = ‘news’ ORDER by post_date DESC LIMIT 5″;

    Just replace wp_terms.slug = ‘news’ in my example with the category slug you need.

    The category is represented by either ID, Name or Slug, so you can use which ever you like.

    For ID, use: wp_terms.term_id=’n’
    For Name, use: wp_terms.name=’Word or words’
    For Slug, Use: wp_terms.slug=’word-or-words’

    Hope this helps.

  71. No 71 by
    Alex

    I’ve already implemented this on my site, but I’d like to call a custom field(such as Image) to display next to the post. I’ve tried a few things, but I’m not having much luck. Any ideas?

    Thanks in advance.

  72. No 72 by
    gdog

    Is it possible to highlight all parts of the code that need changing… I’ve installed this and it’s not working and I’m wondering if there’s something I’ve not changed.

    My files are all .php

    I’ve got the wp config info in the page.

    It’s displaying: : More

  73. No 73 by
    Ian

    Does anyone know how this may work with non php pages?

    I am re designing the look of a clients site without changing the contents (basically creating a new dream weaver template) Without changing anything inside the editable regions where they have done all their SEO.

    All of the site pages are .htm. Most of thier pages rank very strong with the search engines, so thier SEO company does not recomend making any url changes that could effect how they are found.

    As part of the new look I have added a column on the right for a quick contact form and to display Blog exerpts and maybe even tweets thier staff make.

    Any advice would be appreciated.

  74. jamis, is it possible to make a sidebar with all the previous posts and their titles with charlimit to some number and then when clicked on the certain titles post, the whole content displayed.

    any help appreciated.

  75. No 75 by
    Thomas

    I’ve implemented this on my own site and it works like a charm! However, there are two things I would like to configure…

    1) Does anyone know how to write an array (without using php foreach) that will assign H tags (H1, H2, H3…) to the post title?

    2) Is there an alternate to using maxcharacters? The problem with maxcharacters is that it sometimes trims words before they are complete. Is there a way to trim the content by wordcount, instead?

  76. No 76 by
    Brooksy

    Brilliant tutorials and thanks to the people who have kept it up to date with helpful comments.

    I was able to blend this tutorial with your other tutorial and some of the comments to get my site to display 3 excerpts of the 3 most recent posts in 1 of the categories within my blog site.

    so thanks!

  77. No 77 by
    Nick

    Hi, I have also implemented this code and it works magic. Question? How do i get line breaks or paragraph to show as it is on the blog? better yet, how do i get a short form so that someone can click read more?

    As it is, it brings the entire post without line breaks.

    Help.

  78. No 78 by
    rhonda

    I know this is probably has an obvious answer but where or how do you find your database name.

  79. [...] just by opening the first few offerings that google presented i come across this blog post “http://www.jamischarles.com/blog/how-to-add-recent-wordpress-posts-on-an-external-html-page/” from 2007 by Jamis Charles that was excellently written and 100% what i needed [...]

  80. No 80 by
    Matt

    Hi, I got this working, put when the posts are displayed on external page all formatting from the original post is lost? I have to use ASCII character codes to get the text to display correctly? Can any help?

  81. Hiya,
    I have used this code to great success on a client’s site to display their latest blog post, however, a very strange thing has occured, using the EXACT code from this page, and from the WORKING client page, I have tried to replicate this on my own webpage:

    http://www.baysickdesign.com/SiteTest/

    however, now on my own server, I recieve these error messages:

    Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /usr/home/w10134/domains/baysickdesign.com/public_html/SiteTest/index.php on line 17

    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/home/w10134/domains/baysickdesign.com/public_html/SiteTest/index.php on line 23

    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/home/w10134/domains/baysickdesign.com/public_html/SiteTest/index.php on line 24

    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/home/w10134/domains/baysickdesign.com/public_html/SiteTest/index.php on line 25

    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/home/w10134/domains/baysickdesign.com/public_html/SiteTest/index.php on line 28

    I am absolutley stumped as to why its working on one site but not my own!

    Can anyone help with this? Thanks!

    Justin

  82. Hi there. I added your code to my site’s index page so I could display post excerpts there but the post date display is not displaying. The “more” permalink is also not working even though I didn’t change any of the permalink PHP. Plus I decided I did want the display to have some of the blog content, so I took out the “strip the HTML” tag and it didn’t change anything. What should I do?

  83. Like some of the posters, originally I could not figure out how to preserve line breaks because I actually have very little coding knowledge. But I’ve found the solution here:

    http://mu.wordpress.org/forums/topic/14096

    The solution used is str_replace(). I’ve looked through his code, then looked up the php manual and found that chr(13).chr(10) represents a line break.

    So after your line 15:
    $blog_content = mysql_result($query_result, 0, “post_content”);

    I’ve added this line:
    $blog_content=str_replace(chr(13).chr(10), “”, $blog_content);

    which replaces those two characters with a line break, subsequently properly formatting the post.

    Hope this helps.

  84. Sorry for the double post; I forgot to use the code format so my linebreak html got eaten. But in the line I’ve added, between the double quotation marks is supposed to be a br.

Add Your Own


bluehost.com ad


Recent Posts

  • Lessons learned from Apple&#39;s Design Process
  • On why I started another Redesign when I had just finished one.
  • Why I chose Bluehost for cheap, reliable hosting (review)
  • Break; and continue; in javascript loops
  • Writing a prototype function in JavaScript
  • -->