[resolved] Embed only the latest post (9 posts)

  1. sketchee
    Posted 8 years ago #

    I want to embed just the latest post from my wp blog (sketchee.com/wp) on the bottom of my main page. I couldn't figure out how I could do this. Is there a way just to generate an include file that I can use a server side incude to put the file into the html (not php) front page?

  2. tsguitar
    Posted 8 years ago #

    If you are going to include WordPress content on a page, it must be a PHP page (end with a .php or .phtml). The entire page could be static HTML, just give it a .php or .phtml extension.

    Any page that is outside the WP installation can still have WP stuff on it. Just add this to the top of the page:

    <?php require('pathtoyourwordpressinstall/wp-config.php'); ?>

    Check this out:

    So, if you put that little bit of code at the top of the page, this should work to display the most recent post:
    $posts = get_posts('numberposts=1');
    foreach($posts as $post) :
    <a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a>
    <?php the_content(); ?>
    <?php endforeach; ?>

    Here's more information:

  3. tsguitar
    Posted 8 years ago #

    Not wp-config. Use this instead:
    <?php require('./path-to-your-blog/wp-blog-header.php'); ?>

  4. sketchee
    Posted 8 years ago #

    I'll give it a try when I get home this evening. Let you know how it goes! Thanks

  5. sketchee
    Posted 8 years ago #

    Worked great: http://www.sketchee.com Thanks

  6. danmoriarty
    Posted 8 years ago #

    Thanks, keep this around, Very helpful.

  7. Seaborn
    Posted 8 years ago #

    This code isnt working for me, am I doing something wrong. Im using the Static Front Page plugin and editing the "HTML" of home.php.

  8. Seaborn
    Posted 8 years ago #

    Could this just not work in 2.0.4?

  9. carl_in_florida
    Posted 7 years ago #

    When I try this I get


    Can’t select database

    We were able to connect to the database server (which means your username and password is okay) but not able to select the christia_wrdp1 database.

    Any ideas? The blog works just fine.

Topic Closed

This topic has been closed to new replies.

About this Topic