0

I've made a custom front-page.php which includes "the loop" and it works great. I would also like to have a separate page which is the regular old posts page you get from index.php. How do I make a page refer to index.php?

I've tried going to Appearance -> Customize and setting a static front page, but then "the loop" on my main page stops working, so that's not the solution.

3

When a theme has the front-page.php template, it will take over regardless of what you set in the admin pages to be your front page.1 This means you have a couple of options:

  1. Create a page template with your loop and styles that are currently part of front-page.php, apply that template to a new page you create in WP, then assign that new page to be your static front page in the Admin settings (Settings → Reading → Front page displays → Front page).
    Then create a page with your regular loop and styles for your blog index page, assign it to a new page in WP, and set it as the front page for your blog posts (Settings → Reading → Front page displays → Posts page).
  2. Consider adding the home.php template to the mix so that it handles the "regular old posts page."2

I'd recommend #2, since it avoids having to create 2 more pages inside WP that are just there to trigger the template files. Since the loader already looks for the front-page.php and home.php templates, those pages will load faster if the templates are in there and used properly.

UPDATED 1/16

Okay, here's a bit more background...

  • If you have the front-page.php template and "Your latest posts" selected, the home page of your site will use the front-page.php template.
  • If you have the front-page.php template and home.php and "A static page (Front page)" selected but nothing selected for "Posts page", the home page of your site will use the content of the page you selected with the front-page.php template and index.php for posts (ignoring home.php).
  • If you have the front-page.php template and home.php and "A static page (Front page)" selected and a "Posts page" selected, the home page of your site will use the content of the page you selected with the front-page.php template, and the content of the page you selected with the home.php template.

It can get a bit complex, especially since there's so much flexibility involved. It was something I had to go back and play with again just to refresh my understanding.

The main purpose is to have something distinct on the front page (completely different layout, different colors, different header, etc.) while having the option to swap out the home page content just by selecting the page you want to use. You can also have the main blog page slightly different than the rest of your single posts or pages, which is where the home.php comes into play.

/update

Refs:

  • 1
    Using home.php is the way to go here. Note that merely having index.php is also sufficient, since the home page template (i.e. the blog posts index) falls back from home.php to index.php per the Template Hierarchy. – Chip Bennett Jan 15 '14 at 13:47
  • Thank you. I'm trying and trying to make this work. So you say that the first step is to add home.php. I've done that, but I cant find a way to refer to home.php either. Mysite.com/home.php gives me a 404. I've scoured the docs, but I can't find any way to get to home.php except from the front page (which is where I have something else). I tried making home.php into a template but then it turns out that the loop doesn't work on templates. I'm amazed that it's so complicated to get a blog index page in Wordpress. I thought a blog index page would be standard. – guest Jan 16 '14 at 5:00
  • The template files live inside your theme folder and aren't accessed directly through a URL, but are loaded by WordPress based on what kind of page is being displayed. In this case, the contents of front-page.php are displayed when your site's front page is loaded and home.php is displayed when your blog page is loaded (whatever page you set to display your blog posts). So if you have a page called "My Blog Posts", and have that set in the admin to display blog posts, then it will load the home.php template (which should have the loop and any other code you want to use to diplay posts). – Morgan Estes Jan 16 '14 at 16:05
  • But the admin only gives me the option to set a posts page if I set a static front page. And as per my original question, setting it to a static front page stops the loop from working on the front page. – guest Jan 16 '14 at 22:59
  • Sorry, it seems I added to the confusion. I've updated my answer to help clarify things a bit more based on some testing I just completed. – Morgan Estes Jan 16 '14 at 23:35
0

What you want to do is some customization, you wouldn't want default template to work. What you can do is you can create a new template file that would request the type of posts you want and other options like orderby, number_of_posts etc. Simply put the code in a new template file and assign the page that template.

protected by Community Oct 30 '14 at 8:11

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.