WordPress.org

Forums

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

  1. sketchee
    Member
    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
    Member
    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:
    http://wordpress.org/support/topic/82371?replies=20#post-423153

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

    Here's more information:
    http://codex.wordpress.org/Template_Tags/get_posts

  3. tsguitar
    Member
    Posted 8 years ago #

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

  4. sketchee
    Member
    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
    Member
    Posted 8 years ago #

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

  6. danmoriarty
    Member
    Posted 8 years ago #

    Thanks, keep this around, Very helpful.

  7. Seaborn
    Member
    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
    Member
    Posted 8 years ago #

    Could this just not work in 2.0.4?

  9. carl_in_florida
    Member
    Posted 7 years ago #

    When I try this I get

    WordPress

    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