WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] how to show the last post on a static wordpress page?

[Resolved] how to show the last post on a static wordpress page?

  • marcnyc

    @marcnyc

    is there a way that I can show the title AND content of the last post of my blog on a static page that I use as the home page of my site?
    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Mark Ratledge

    @songdogtech

    Forum Moderator

    A new query that won’t interfere with the main loop. You have to enable php execution with something like Exec-PHP « WordPress Plugins.

    <?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
    <?php the_title(); ?></a>
    <?php the_content(); ?>
    <?php endwhile; ?>

    Thanks for helping out.

    I do have Exec-PHP installed and activated but this code you offered doesn’t seem to show anything. Is this supposed to work for “pages” and not just “posts”?

    Moderator Mark Ratledge

    @songdogtech

    Forum Moderator

    Did you change mycategory to a name of one of your categories?

    Or you could just remove this from the supplied code:
    category_name=mycategory&

    Just to display the last post regardless of category.

    thanks that helped and explained everything!!
    THANK YOU SO MUCH to both of you for taking the time

    Thanks guys….. I used this as well.

    I deleted the category line as mentioned.

    Thanks for keeping the forum alive!!!!!

    Thanks for this code! I’ve been searching for hours trying to figure this out.

    Is there a way to make this only show the excerpt instead of the whole post?

    If you use excerpts, try changing the_content() to the_excerpt().

    Otherwise, try the following:

    <?php global $more;?>
    <?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <?php $more = 0;?>
    <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
    <?php the_title(); ?></a>
    <?php the_content(' Read more...'); ?>
    <?php endwhile; ?>

    Basically I’m not that bright as I changed the_post() to the_excerpt() earlier instead of the_content() ha! That definitely worked though…thanks!

    Now I just have to figure out why all my ellipses aren’t a link on my static homepage or my blog and I should be set with what I’m trying to do!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] how to show the last post on a static wordpress page?’ is closed to new replies.
Skip to toolbar