0

I'm creating a wordpress theme for a client to use in his existent wordpress site. Anyways, I've completed the theme except one specific thing. I see that he has lots of pages with the keyword Module in the title. Example of the title would be "How to create this product: Module 1." In his previous theme, they had a wordpress page template - page-module.php use specifically for these pages. However, I created a wp page template in my theme with the same name but when I go to any of these pages, it is displaying the default page.php template instead of the page-module.php template. When I switch back to his theme, it work fine with his page-module.php template but when I switch by to my theme, it doesn't work. Can someone please help me understand why it's not working with my theme?

closed as unclear what you're asking by Michael, cjbj, Dave Romsey, Pat J, bueltge Nov 3 '16 at 7:29

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Are you asking how selectable page templates work? – Tom J Nowell Oct 24 '16 at 23:45
0

You can adjust the template to use in the fly based on the type of page you're viewing. https://codex.wordpress.org/Plugin_API/Filter_Reference/template_include

add_filter( 'template_include', 'portfolio_page_template', 99 );

function portfolio_page_template( $template ) {

    if ( is_page( 'portfolio' )  ) {
        $new_template = locate_template( array( 'portfolio-page-template.php' ) );
        if ( '' != $new_template ) {
            return $new_template ;
        }
    }

    return $template;
}

You could use that in conjunction with https://codex.wordpress.org/Function_Reference/get_queried_object to check out information about the page requested, like the title.

This assumes you didn't just set your page template on the page itself.

setting Page Template

  • Hi @jgraup, thanks for the reply. All the page templates are set to default. I added the code you give me to the function file of my theme but it is still not working. I don't know why. – Prince J Oct 26 '16 at 20:59
  • The code is an example, which checks for a specific page, you'd need to supply your own custom condition . At the very least just remove everything except for your custom template path to make sure that works. Then come up with a way to only function on the required pages. – jgraup Oct 26 '16 at 21:02
  • My page template is page-module.php, so this is how I did it. code add_filter( 'template_include', 'module_page_template', 99 ); function module_page_template ( $template ) { if ( is_page( 'module' ) ) { $new_template = locate_template( array( 'page-module.php' ) ); if ( '' != $new_template ) { return $new_template ; } } return $template; } – Prince J Oct 26 '16 at 21:21
0

It sounds like they were using custom page templates. You'll want to read about Page Templates on the codex.

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