Support » Fixing WordPress » How to know if a page template is being used?

  • I am dabbling in the mysteries of front-page.php and home.php.

    Here’s my scenario:
    I have front-page.php. I also have home.php. Now, the user, in her innocence, goes to Setting>Reading and sets the Front Page to be a static page and set the Blog Posts page to be “Blog Home”.

    But I want to give more than one option for front page layouts. So I have front-page.php, and I have another-template-for-fp.php. The user makes a front page, sets the template to another-template-for-fp.php.

    The user, in her innocence, goes to Setting>Reading and set the front page to be a static page. The same static page that is based on the template another-template-for-fp.php.

    WordPress of course keeps using front-page.php.

    I have used Chip Bennet’s advice (isn’t he a great guy!?!) and have the following code in my front-page.php

    if ( 'posts' == get_option( 'show_on_front' ) ) {
    	 /*
    	  * Checks if the blog posts is set to display as front page, so calling home.php instead
    	  */
    
        include( get_home_template() );
    } else {
             //show the front-page.php stuff
    }

    But how on earth do I show the template another-template-for-fp.php ? WP defaults to front-page.php, regardless of the love that is present elsewhere!? Help please!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Why do you have both home.php and front-page.php?

    Thread Starter Momekh

    (@momekh)

    Isn’t that the million dollar question!!

    I kid you not, this will probably be the first and the last time I have them!

    For the reason as to why I have them? Well, WP had them. I thought they were there for a good enough reason for me to emulate.

    I am right now thinking that at most I need a home.php to stylize the blog list view. And then have as many template I want for the front page display, that the user can set in the Setting>Reading section.

    What would you recommend @esmi?

    I thought they were there for a good enough reason for me to emulate.

    Do you also have an index.php template file?

    The problem you have is that front-page.php is always used as the template for a site’s front page – irrespective of that template has been set in the Page attributes. If you want to maximise front page template choice, then I’d suggest getting rid of the front-page.php template file name and using something like default-front.php. That way, a static front page will default to page.php with will then leave both default-front.php and another-template-for-fp.php available to chose from instead.

    Thread Starter Momekh

    (@momekh)

    That’s effectively what I’ve done now. I have used Chip Bennet’s advice found on this page. The way it’s done is that it technically does render the front-page.php file useless.

    Now I really don’t know why I have it in the theme. 🙂

    Thank you so much for your advice @emsi. It helps me gain a bit of confidence in what I have ended up doing.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to know if a page template is being used?’ is closed to new replies.