• Is it possible to make a post template to use for one post only? I want to have my site setup to have the 5 most recent posts displayed on the homepage, with the first/top one being sticky or permanent and having a different look and feel (like, no comments links or date etc.)… I know how to modify the theme to make this possible for ALL posts by modifying the single.php file but how do I do this for only one post? Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • I don’t understand. Do you mean you want only one specific post and only that one post to be formatted differently? Or do you mean that you want the top static post whatever it may be to be formatted differently? Or do you mean that you want one post to show up on a page by itself and be formatted differently?

    Thread Starter lilqhgal

    (@lilqhgal)

    One post will be stickied to the homepage. That one post I want to have a different template/design than the rest of the posts. On all other pages, that post will not appear.

    You can apply style conditionally using the is_sticky() Conditional tag. Use it to add an additional class to your sticky post’s <div>. I kinda expected that WP would have done this but it looks like it doesn’t.

    It does if you use <div <?php post_class();?>> in your templates instead of <div class="post">.

    esmi, good to know. Thanks.

    Thread Starter lilqhgal

    (@lilqhgal)

    Ok so using the is_sticky() how would I modify the index.php so that it says:

    If is_sticky()
    –display THIS html–

    else if
    –display this OTHER html–

    I grasp the concept but I’m not 100% sure how to write the proper code. Thanks!

    Thread Starter lilqhgal

    (@lilqhgal)

    Nevermind I think I figured it out! So far it looks good! ?? Thanks for all the help!

    Yes, but as esmi pointed out if you use post_class() in your templates you may save yourself some trouble.

    I want to do something similar but not sure how…

    Basically I want specific posts to use specific templates.

    Like a page would use a specific template.
    Is this possible?

    so post id 1271 uses the custom template 1271.php

    Make sense?

    If you want to format some posts differently you can filter based on $post->ID and you wouldn’t have to actually create a new template.

    You can also just reformat the post using CSS if you know the post IDs.

    If you do want to use a radically different template altogether– different header, different footer etc– then filter based on $post->ID and redirect before get_header() and I think you’ll be okay. But I’ve never really thought about this before, much less actually try to do it.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Post template for one post?’ is closed to new replies.