• Seaborn

    (@joyhog)


    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:

    https://www.ads-software.com/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?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Kafkaesqui

    (@kafkaesqui)

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

    Leovenous

    (@leovenous)

    This was very helpful to me. Mega-props!

    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”

    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.

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

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

    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?

    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.

    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.

    how to show the read more link ?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Page template that displays Post loop’ is closed to new replies.