• This should be easy, but the docs have been no help. I’ve also already tried googling, and three different plug-ins (WP-last post, customizable-post-listings, and recent-posts) but no joy. Each plug-in doesn’t quite do what I want, or screws up (like pulls in a Page as a recent Post).

    What I want to do is: show the latest post (not page, only a blog post) on my custom index.php, regardless of category. Can anyone just give the right wp_query (or whatever template code) to run? I don’t want to limit the number of posts for other pages, like category pages, so setting the Options is out. Thanks.

    Shev.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    On a theme’s index.php page: Just add <?php query_posts($query_string . "&showposts=1"); ?> to the index.php file, somewhere before the loop.

    Since the index.php file is the fallback for all pages (category archives, etc), you’ll need specific templates specifically for those pages (like category.php) in order for them to not inherit this one post rule though.

    Thread Starter odonian

    (@odonian)

    Thanks Otto42 – since I’m using someone else’s theme and there’s no category.php file, does that mean I’ll need to create one?

    Is there an easier way to control what happens on the homepage, without screwing up other pages using the loop? I’m just incredulous that WP doesn’t have this kind of flexibility.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    You asked about changing index.php, not about changing the home page.

    If you just want to change the home page and nothing else, then copy the index.php into home.php and change home.php instead. Then home.php will be used for the home page, and index.php for everything else.

    Also, I don’t understand what you’re talking about; WordPress is incredibly flexible with how it displays different pages. That’s the whole point of the Template Hierarchy.

    http://codex.wordpress.org/Template_Hierarchy

    Easy to understand chart:
    http://www.scoutpress.de/download/wp_Template_Hierarchy.png

    Thread Starter odonian

    (@odonian)

    OK, thanks for the pointers, I got it to work the way I want.

    If anyone is interested, I wrote a plugin that does something similar. Check out the main page in my profile link. At the moment, there is only one post there, but it will list the latest five non-event posts.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to only show the latest post on custom index.php?’ is closed to new replies.