[英]WordPress call to undefined function in_category()
我在我的二十三子主題的wp-content/themes/twentythirteen-child/content.php
模板中有這個條件 function,用於在博客存檔頁面上的某些帖子上方添加橫幅。
if (in_category(get_theme_option('banner_1_category'))
&& (! is_category(get_theme_option('banner_1_category'))))
{
echo "<div id=\"banner-1\"><h3>".get_theme_option('banner_1_text')."</h3></div>";
}
....
它工作沒有問題。
現在我轉向 Avada 子主題,相應的模板是wp-content/themes/avada-child/templates/blog-layout.php
。 當我將上述代碼放入此模板中時,出現以下錯誤:
致命錯誤:調用未定義的 function in_category()
我不太明白這怎么可能是“未定義的”,因為in_category()
是 WordPress 的核心 function 。 我用谷歌搜索了這個錯誤,但沒有找到很多結果。 似乎通過向wp-load.php
文件添加require_once()
解決了類似的錯誤。
require_once('/home/my-server-path/wp-load.php');
我試着把它放在我的條件之前,但沒有任何區別。
為什么 WordPress 的核心 function 在 Avada 中不起作用,我該如何解決?
我正在運行最新版本的 WordPress (5.2.3) 和 Avada (6.0.3)
編輯:
沒有提到上面的條件 function 是通過include
注入到模板中的
include 'my-path/includes/banners.php';
在職的:
wp-content/themes/twenty-thirteen-child
↳ archive.php ('get_template_part' content-cpt.php)
↳ content-cpt.php ('include' includes/banners.php)
↳ includes
↳ banners.php
(致命錯誤:調用未定義的 function in_category()
):
wp-content/themes/avada-child
↳ archive.php ('get_template_part' templates/blog-layout.php)
↳ templates
↳ blog-layout.php ('include' includes/banners.php)
↳ includes
↳ banners.php
我將include
更改為get_template_part()
,然后又重新工作了。 為了做到這一點,我不得不將文件名修改為blog-banners.php
。
get_template_part('includes/blog', 'banners');
但是,我無法解釋為什么“二十十三”中的include
內的WordPress核心功能可以正常工作,但是在不同模板內的同一include
的相同WordPress核心功能卻在Avada中產生“未定義”錯誤。 這兩個主題都使用一系列get_template_part()
函數來結束插入條件的模板。 唯一的區別是,在其中插入我的include的Avada模板位於主題的子目錄中,但是在《二十十三》中,它位於主題的根目錄中。
在有人發布更好的答案來詳細解釋此致命錯誤之前,我將接受自己的答案。
我的橫幅有這個問題。 WordPress 中的掛鈎希望您使用 isset 而不是。:這是一個 pagebanner 的示例 function 我已更正以解決此問題:
if(isset($args['title'])){
}else{
$args['title'] = get_the_title();
}
if(isset($args['subtitle'])){
}else{
$args['subtitle'] = get_field('page_banner_subtitle');
}
if(isset($args['photo'])){
}
elseif (get_field('page_banner_background_image') AND !is_archive() AND !is_home() ) {
$args['photo'] = get_field('page_banner_background_image')['sizes']['pageBanner'];
}
else{
$args['photo'] = get_theme_file_uri('/images/ocean.jpg');
}
?>
<div class="page-banner">
<div class="page-banner__bg-image" style="background-image: url(<?php echo $args['photo']; ?>);"></div>
<div class="page-banner__content container container--narrow">
<h1 class="page-banner__title"><?php echo $args['title'] ?></h1>
<div class="page-banner__intro">
<p><?php echo $args['subtitle']; ?></p>
</div>
</div>
</div>
<?php }```
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.