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

Viewing 11 replies - 1 through 11 (of 11 total)
  • <?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;
    ?>
    Thread Starter frogspot

    (@frogspot)

    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

    Thread Starter frogspot

    (@frogspot)

    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
    ____________________________________________________

    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.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

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

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

    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.

    Thread Starter frogspot

    (@frogspot)

    Thanks Moshu,

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

    –Steve

    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 www.remarpro.com was also helpful.
    Many thanks!

    Thread Starter frogspot

    (@frogspot)

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

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Integrating top blog post into regular web page’ is closed to new replies.