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?
2 Answers
Reset to default 3This is just a supplement to the other answer.
I am trying to load
fd-blog.php
if it is the 'Blog' page, otherwise load thefd-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
版权声明:本文标题:php - get_template_part for specific page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745299692a2652296.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
-
). Justinc/fd
as inget_template_part( 'inc/fd', 'blog' );
– Sally CJ Commented Jul 24, 2019 at 8:29get_tempalte_part
- that should beget_template_part
- inget_tempalte_part( 'inc/fd-', 'default' );
– Sally CJ Commented Jul 24, 2019 at 8:34