[wp-hackers] the home.php problem: does it asks for a posts.php ?
chip at chipbennett.net
Mon Aug 27 21:27:34 UTC 2012
You might want to revisit the Template
It appears that you use "home.php" and "front-page.php" interchangeably,
but they are not interchangeable.
- The "front-page.php" template file is used to render the SITE FRONT
PAGE (i.e. home_url()), regardless of whether the front page displays the
blog posts index, or a static page.
- The "home.php" template file is used to render the BLOG POSTS INDEX,
whether the blog posts index is displayed on the site front page, or on a
If your goal is to modify the *site front page* content, then you should
*always* use "front-page.php" for this purpose, and NOT "home.php".
So, your Solution 1 isn't necessary:
Solution 1 - Page template
You create a page template, with a simple code that executes query_posts()
and load your index.php.
This is not a good solution for at least 2 reasons. First, body_class()
does not work well in this situation. Second, it requires the user to
create the page and assign the template, this means he/she can break the
site if this page is edited or deleted
Assuming your Theme includes an "index.php", you don't need to make any
other template-file changes. You *can* include a "home.php", but it's not
Side note: you should *never* be using query_posts(), for anything.
Avoiding the conflation of "home.php" and "front-page.php" should explain
why Solution 2 is also not necessary:
Solution 2 - Use the Reading settings as usual, and create 2 page
templates. In this case, you will probably have to edit the name of your
home.php file because sometimes it conflicts with these options. In other
words, this scenario makes home.php useless.
The "home.php" template file is only useless if "front-page.php" exists,
and the site front page is set to display the blog posts index. But that's
as intended. The "front-page.php" template file is intended to be used to
define some *custom* content for the site front page. If you merely want to
customize the blog posts index layout/style, use "home.php".
So, isnt it a good idea to have a posts.php template?
Hopefully you see now what that is unnecessary? What you propose as
"posts.php" is exactly the purpose and intent of "home.php".
On Mon, Aug 27, 2012 at 4:11 PM, Leo germani <leogermani at gmail.com> wrote:
> Hi all,
> Imagine you create a home.php or front-page.php template in your theme.
> Ok, now the visitor sees this template when visiting your sites front page.
> You can put anything you want there, in a template totally different from
> the blog template. Cool.
> Now you want to have a link to the lists of posts of your site, right? Of
> course it should be easy. But here you get in a weird situation with no
> good solution so far.
> Solution 1 - Page template
> You create a page template, with a simple code that executes query_posts()
> and load your index.php.
> This is not a good solution for at least 2 reasons. First, body_class()
> does not work well in this situation. Second, it requires the user to
> create the page and assign the template, this means he/she can break the
> site if this page is edited or deleted
> Solution 2 - Use the Reading settings as usual, and create 2 page
> templates. In this case, you will probably have to edit the name of your
> home.php file because sometimes it conflicts with these options. In other
> words, this scenario makes home.php useless.
> So, isnt it a good idea to have a posts.php template? Lets think about this
> We have now post type archives, so, in theory, we could have a
> archive-post.php and if we access mysite.com?post_type=post we would see
> our blog there. It works, but it does not look very good when we're using
> beatiful permalinks.
> If we follow the same structure we have for others CPTs, visiting
> mysite.com/post would take me to the same place. But it does not, because
> this rewrite rule doesnt exist.
> Adding this rule could be a solution, but not a good one. /post/ is not a
> good URI for a blog.
> So what I think that could be done:
> . add a default rewirte rule that redirects /blog/ (or /posts/) to
> ?post_type=post (and then we use archive-post.php in our theme).
> . add an option in the permalinks page that lets the user change the posts
> base URI, as they do with categories and tags.
> What do you think about that?
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers