0

I am getting too frustrated while creating new home page using template in Storefront theme. https://wordpress.org/themes/storefront/.

With the help of this https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/ i tried bt not getting success.. anyone can tell me how can i do this without plug-in..

I want to change home page , and want to show my custom template home page. –

Template Script

<?php
/**
 * Template name: Homepage My Custom
 *
 * @package storefront
 */

get_header(); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
            **My Custom Home Template**
        </main><!-- #main -->
    </div><!-- #primary -->
<?php get_footer(); ?>

2 Answers 2

1

First step in modifying a theme, is creating a child theme.

Now that you have a theme that is basically the same as the original, you can simply copy files of the original theme that you want to modify into exactly the same relative location as in the original theme and modify them to whatever you need. In your specific case, after locating the page template for the home page and copying it you can just modify the code in it and there is no need to create a new one.

2
  • hi thankx.. I did not tries Child theme. But i think i have find out the issue.. My template name is not listing in Wordpress admin menu .. I tried with Twenty twelve bt same issue , template name not is in List during add page.
    – Naresh
    Commented Dec 2, 2015 at 16:06
  • In any case you should do a child theme otherwise you will loose your changes when you upgrade the theme. As for not finding the template, have you tried to place it in the root directory of the theme? Commented Dec 2, 2015 at 18:51
0

First create a new page in theme directory

example template-newhomepage.php (Copy of template-homepage.php)

Change theme name to

Template name: New Homepage

Next step is to Change:

do_action( 'homepage' );

to

do_action( 'homepagenew' );

For create homepagenew hook in hook.php

Follow directory path:

/wp-content/themes/storefront/inc/structure

add this code under homepage hook:

add_action( 'homepagenew', 'storefront_homepagenew_content', 10 );
add_action( 'homepagenew', 'storefront_product_categories', 20 );
add_action( 'homepagenew', 'storefront_recent_products',  30 );
add_action( 'homepagenew', 'storefront_featured_products', 40 );
add_action( 'homepagenew', 'storefront_popular_products', 50 );
add_action( 'homepagenew', 'storefront_on_sale_products', 60 );

Next thing we have to do is add below code in template-tag.php in same directory:

if ( ! function_exists( 'storefront_homepagenew_content' ) ) {
/**
  * Display homepage content

* Hooked into the `homepage` action in the homepage template

* @since  1.0.0
  * @return  void
  */
function storefront_homepagenew_content() {

while ( have_posts() ) : the_post();
   get_template_part( 'content', 'newhomepage' );

endwhile; 
// end of the loop.

}
}

Now Create a Content-newhomepage.php file replica of content-homepage.php in theme directory

/wp-content/themes/storefront/

Now you can create a New homepage in WordPress admin and assign template "New Homepage" to this page.

4
  • Modifying themes without making a child theme is a big no no Commented Dec 2, 2015 at 12:19
  • You are right, but as per the question the user wants to do the customization within the same theme. Commented Dec 2, 2015 at 12:28
  • Many times a user want to do the wrong thing. You are more then welcome to give him the rope to hang himself, but at least tell him that in the end of the process he is going to die ;) ( the end here - theme upgrade) Commented Dec 2, 2015 at 12:33
  • I know not a Good Solution. But its not a Bad solution that some one mark -1 . i agree with you. With your solution we can customize theme, if we do not want to update Theme.. +1 for you.
    – Naresh
    Commented Dec 4, 2015 at 7:37

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