Forums

Integrating top blog post into regular web page (12 posts)

  1. FrogSpot
    Member
    Posted 8 months ago #

    I would like to display the most resent post in my blog as a teaser on my regular homepage.

    It seems that I should be able to just use a php include to get the same info that WordPress gets from the mysql database but I have not been able to figure out how WordPress does it.

    Anyone know how to do this?

  2. whooami
    Member
    Posted 8 months ago #

    <?php require('path/to/wp-blog-header.php');
    query_posts('showposts=1');
    while (have_posts()) : the_post(); ?>
      <?php the_title(); ?>
      was just posted in
      <?php the_category(', ') ?>
      <a href="<?php the_permalink() ?>" rel="bookmark">Read More</a>
    </p>
    <?php endwhile;
    ?>
  3. FrogSpot
    Member
    Posted 8 months ago #

    Thanks for your response.

    The code you sent only gave the title and said the category it was posted in. I'd like the actual text of the post. is that possible?

    Here's a sample of what I'd lie displayed on my homepage.
    ___________________________________________________________
    Title
    THis is just some text to fill the text of my article that is the top post in the blog.

    By Steve posted (date)

    Read more View My blog
    ________________________________________________________

    I don' really need the categories listed here.

    Thx

  4. FrogSpot
    Member
    Posted 8 months ago #

    Oops, I lost my formating on the sample when I posted the message. I'll try again:

    ___________________________________________________________
    Title
    This is just some text to fill the text of my article that is the top post in the blog.

    By Steve posted (date)

    Read more...........................View My blog
    ____________________________________________________

  5. moshu
    Moderator
    Posted 8 months ago #

  6. artsmo
    Member
    Posted 8 months ago #

    The code above didn't work for me regardless of whether I used a relative or absolute pathname for require wp-blog-header.php, or whether I used the directory name or the subdomain URL. I used the code exactly as given, except to specify my own pathname.

    Is there some PHP trick I am missing?

    Details: Two WP 2.2.2 installations, each in its own directory, of course. Working with just one to pull recent posts onto a regular home page. Can't give URL, site is being developed for a client.

  7. Otto42
    Moderator
    Posted 8 months ago #

    No trick. You use the relative directory path and filename. Not the URL, not ever.

  8. artsmo
    Member
    Posted 8 months ago #

    "The code above didn't work for me regardless of whether I used a relative or absolute pathname for require wp-blog-header.php"

    I figured as much, and I did try a relative pathname first, but that didn't work either. From index.html in the root directory, to the "consumers" directory where the blog is installed (shown without full syntax):
    php require('consumers/wp-blog-header.php')

    Anyway, using exactly as described, via plain text editor cut & paste of whooami's code, and using the relative pathname has not worked.

    But thanks, anyway.

  9. whooami
    Member
    Posted 8 months ago #

    From index.html in the root directory, to the "consumers" directory where the blog is installed (shown without full syntax):
    php require('consumers/wp-blog-header.php')

    you cant use php inside a file named index.html

    that wont work. .html files are static and php inside of them will not be parsed server-side.

    If you rename your index.html to index.php, and try what I suggested you will see that it works as I provided (assuming you use the right path to wp-blog-header.php).

    --

    I really should say that you CAN actually use php inside .html files, BUT that it requires an .htaccess tweek - which I am sure you probably have not made.

  10. FrogSpot
    Member
    Posted 8 months ago #

    Thanks Moshu,

    I was able to figure it our from the tutorial you linked to.

    --Steve

  11. artsmo
    Member
    Posted 8 months ago #

    Thanks, whooami. I did finally save the file with the .php extension, but still had a problem until I discovered that my plain text editor (Mac TextEdit) messed up the quotes instead of rendering them in plain text. Another of your replies on wordpress.org was also helpful.
    Many thanks!

  12. FrogSpot
    Member
    Posted 3 weeks ago #

    I would like to modify the code above (from Whooami) to display the information for a specific category. Any hints?

Reply

You must log in to post.

About this Topic