admin管理员组

文章数量:1418907

I have tried adding a file inside my header.php, but it will not load correctly. I get this error:

Fatal error: Uncaught Error: Call to undefined function get_tempalte_part()

Here is my markup in my header.php:

<html class="m-0">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>*TITLE*</title>
        <?php wp_head(); ?>
    </head>

    <body <?php body_class(); ?> >

            <section id="header" class="container-fluid no-gutters">

                <?php
                if( is_page( 'blog' ) ) {
                    get_template_part( 'inc/fd-', 'blog' );
                } else {
                    get_tempalte_part( 'inc/fd-', 'default' );
                }
                ?>

                <?php if( is_search() ) {
                    fd_title_search();
                } else if( is_product() || is_account_page() || is_page( 'contact-us' ) || is_page( 'shipping' ) || is_page( 'privacy' ) || is_page( 'terms' ) || is_page( 'faq' ) || is_page( 'about-us' ) || is_page( 'home' ) ) {
                    echo '';
                } else if( is_product_category() ) {
                    fd_title_product_category();
                } else if( is_shop() ) {
                    fd_title_shop();
                } else if( is_page( 'wishlist' ) ) {
                    fd_title_wishlist();
                } else {
                    fd_title_default();
                } ?>

            </section>

I am trying to load fd-blog.php if it is the 'Blog' page, otherwise load the fd-default.php, but I keep getting an error, no matter what I try! What am I doing wrong?

I have tried adding a file inside my header.php, but it will not load correctly. I get this error:

Fatal error: Uncaught Error: Call to undefined function get_tempalte_part()

Here is my markup in my header.php:

<html class="m-0">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>*TITLE*</title>
        <?php wp_head(); ?>
    </head>

    <body <?php body_class(); ?> >

            <section id="header" class="container-fluid no-gutters">

                <?php
                if( is_page( 'blog' ) ) {
                    get_template_part( 'inc/fd-', 'blog' );
                } else {
                    get_tempalte_part( 'inc/fd-', 'default' );
                }
                ?>

                <?php if( is_search() ) {
                    fd_title_search();
                } else if( is_product() || is_account_page() || is_page( 'contact-us' ) || is_page( 'shipping' ) || is_page( 'privacy' ) || is_page( 'terms' ) || is_page( 'faq' ) || is_page( 'about-us' ) || is_page( 'home' ) ) {
                    echo '';
                } else if( is_product_category() ) {
                    fd_title_product_category();
                } else if( is_shop() ) {
                    fd_title_shop();
                } else if( is_page( 'wishlist' ) ) {
                    fd_title_wishlist();
                } else {
                    fd_title_default();
                } ?>

            </section>

I am trying to load fd-blog.php if it is the 'Blog' page, otherwise load the fd-default.php, but I keep getting an error, no matter what I try! What am I doing wrong?

Share Improve this question asked Jul 24, 2019 at 8:22 Anake.meAnake.me 2462 silver badges11 bronze badges 3
  • 1 This doesn't answer the question, but there's no need for the dash (-). Just inc/fd as in get_template_part( 'inc/fd', 'blog' ); – Sally CJ Commented Jul 24, 2019 at 8:29
  • 1 And there's a typo: get_tempalte_part - that should be get_template_part - in get_tempalte_part( 'inc/fd-', 'default' ); – Sally CJ Commented Jul 24, 2019 at 8:34
  • 1 @SallyCJ, It actually helped solve my problem! One was the typo (how embarrassing) and the other was the unnecessary trailing dash! All working! Please submit it as an answer so I can mark it accordingly. – Anake.me Commented Jul 24, 2019 at 8:42
Add a comment  | 

2 Answers 2

Reset to default 3

This is just a supplement to the other answer.

I am trying to load fd-blog.php if it is the 'Blog' page, otherwise load the fd-default.php

To actually load the template file, you should remove the dash (-):

get_template_part( 'inc/fd', 'blog' );    // loads inc/fd-blog.php
get_template_part( 'inc/fd', 'default' ); // loads inc/fd-default.php

So just inc/fd, and here's the relevant code in get_template_part:

// Example when you call get_template_part( 'inc/fd', 'blog' ), $name below is 'blog'.
if ( '' !== $name ) {
    $templates[] = "{$slug}-{$name}.php";
}

You've spelt it wrong: get_tempalte_part, "tempalte", needs to be get_template_part().

本文标签: phpgettemplatepart for specific page