WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how to show the last post on a static wordpress page? (10 posts)

  1. marcnyc
    Member
    Posted 4 years ago #

    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

  2. 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; ?>
  3. marcnyc
    Member
    Posted 4 years ago #

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

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

  5. xdesi
    Member
    Posted 4 years ago #

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

    Just to display the last post regardless of category.

  6. marcnyc
    Member
    Posted 4 years ago #

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

  7. pathfinder_05
    Member
    Posted 4 years ago #

    Thanks guys..... I used this as well.

    I deleted the category line as mentioned.

    Thanks for keeping the forum alive!!!!!

  8. metzbgsu
    Member
    Posted 4 years ago #

    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?

  9. vtxyzzy
    Member
    Posted 4 years ago #

    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; ?>
  10. metzbgsu
    Member
    Posted 4 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic