WordPress.org

Ready to get started?Download WordPress

Forums

Page template that displays Post loop (11 posts)

  1. Seaborn
    Member
    Posted 7 years ago #

    I have been searching for a good 2 days on this topic. Found some good help but none of it is really working, I'm wondering if Im doing something wrong or if it's a 2.0.4 issue.

    I am currently using the Static Front plugin to display a page as my homepage. What I would like to do is have the latest post - no matter what category - be displayed before the page content. I realize this is going to be a template issue and its going to involve running multiple loops, its just not working out for me. The closest thread I came accross that helps is this:

    http://wordpress.org/support/topic/35991?replies=17

    What I am looking for is a chunk of code that I can insert into the default page template that will display the latest post. I have tried a couple options and they do display the post, only the page content does not follow. Can someone please help me here?

  2. Kafkaesqui

    Posted 7 years ago #

    Here's a simple bit of code (Ok perhaps not simple, but it's brief) you can stick in your Page template that will show the latest post but should not whack the Page's content:

    <?php $latest = new WP_Query('showposts=1'); ?>
    <?php $latest->the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>

    Customize how the post is displayed to suit your needs.

    EDIT: Should probably explain the lack of a post loop (ala The Loop). Since we're only calling up a single post, there's no need to iterate through the object we've created ($latest). But if you need to collect and display more than one post (let's say it's 5), modify the code from above to:

    <?php $latest = new WP_Query('showposts=5'); ?>
    <?php while( $latest->have_posts() ) : $latest->the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
    <?php endwhile; ?>

  3. Leovenous
    Member
    Posted 7 years ago #

    This was very helpful to me. Mega-props!

  4. stealthgear
    Member
    Posted 7 years ago #

    thanks!!!! This just put me back on schedule to making my portal page. I had just about given up. I am using it in conjunction with "Static Front"

  5. bgajus
    Member
    Posted 6 years ago #

    This has been very helpful for what I am trying to do. I just need to take it one step further. I want to only show posts with the category of "News." Hoping someone can help me out with this.

  6. moshu
    Member
    Posted 6 years ago #

    Try
    showposts=5&cat=XX
    or something like that.

  7. bgajus
    Member
    Posted 6 years ago #

    I messed with that a bit.....but no go. =\

  8. bgajus
    Member
    Posted 6 years ago #

    Ok it works if I give it the category number such as cat=3 or cat=5

    I'm not really sure where it is assigning the cat variable but i'd like to be able to somehow do this by category name rather than it's cat number. Any idea?

  9. nthnlsmmrs
    Member
    Posted 6 years ago #

    Wow, that is extremely helpful. However, as bgajus suggested, I would also like to be able to display posts by category. If there is a method to modify that code to display items from a specific category and set a variable from the page to that value... for instance, using the page title as the post category. So that, I could make a specific "Rants" page, that has the page content, and then a certain number of the rants. Man, I need to sit down and learn this PHP stuff. It's fascinating so far... still confusing as all heck though.

  10. nolageek
    Member
    Posted 6 years ago #

    This is exactly what I'm looking for. Is there a way to get it to paginate like on the front page? (only show x number of posts... etc.

  11. gspark
    Member
    Posted 6 years ago #

    how to show the read more link ?

Topic Closed

This topic has been closed to new replies.

About this Topic