The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Display single post view instead of index page view (2 posts)

  1. 123jonny
    Posted 7 years ago #

    Sorry, not sure where to post this...
    Disclaimer: I can follow and edit *some* php, so hopefully what I'm trying to do isn't outta my reach.

    Instead of a user hitting my domain and seeing the typical list view of the posts (index.php), I'd like to push them directly into the most recent post, in the single page view (single.php). The REASON I'd like to do this is because I intend to apply custom styling (via a custom field) to certain posts at times.

    My current approach was this... I have the custom CSS being detected just fine using a custom field and some extra PHP in the header to look for that field. I then limited the number of posts displayed at a time to 1. Next, I tried "forcing" the index.php to display as the single.php essentially by duplicating the code from single into the index. ...Well, it displays and navigates just fine, but it's still seeing things in list view instead of the single page view, and it's not detecting the custom style/field. Looking at the URLs in this current approach, I can see that it's not displaying the permalink page for each post as I intended, but rather treating them as pages from the post list (URLs read like http://www.domain.com/pages/2/ instead of http://www.domain.com/2009/test-post).

    Hope this makes sense, and perhaps someone can provide some clarity! If I am approaching this completely backwards, please enlighten me! It was the only approach I could see off the top of my head, and I've found little to no additional info on executing this.

    Thanks in advance,

  2. esmi
    Forum Moderator
    Posted 7 years ago #

    Why not use the standard index.php template but, just before the Loop, add query_posts('showposts=1');

Topic Closed

This topic has been closed to new replies.

About this Topic