wordpress术语存在条件不起作用


wordpress term exists condition not working

我在WordPress中的一个循环中运行这个:

<?php
    if ( term_exists('term'=> 'pdf'))
    { 
       echo 'PDF' ;
    }
    else if ( term_exists('term'=> 'ppt'))
    { 
       echo 'PPT' ;
    }
    else ( term_exists('term'=> 'mov'))
    {
        echo 'MOV' ;
    }
?>

我创建了一个名为file-formats的分类法,上面的这些术语(pdfmovppt)在我的file-formats分类法中。

我正在尝试echo特定的东西,这取决于帖子的使用期限。

但上面的PHP脚本似乎只是让网站崩溃了。有人能帮忙吗?


更新

这仍然不起作用。。。

<?php
    if (term_exists( 'term' => 'pdf' )) {
        echo 'PDF' ;
    }
    else if (term_exists( 'term' => 'ppt' )) {
        echo 'PPT' ;
    }
    else if (term_exists( 'term' => 'mov' )) {
        echo 'MOV' ;
    }
    else {
        echo '' ;
    }
?>

检查您的else部件。应为:


if ( term_exists('term', 'pdf')) { 
     echo 'PDF' ; 
 }
 else if ( term_exists( 'term', 'ppt')) { 
   echo 'PPT' ; 
 }
 else { 
    echo 'MOV' ; 
 }

参考:term_exists($term,$taxonomy)

term_exists的第一个参数应该是您的术语("pdf"或"ppt"等),第二个参数-分类法(在您的情况下为"文件格式")。

if (term_exists( 'pdf', 'file-formats' )) {
   echo 'PDF' ;
} else if (term_exists( 'ppt', 'file-formats' )) {
   echo 'PPT' ;
} else if (term_exists( 'mov', 'file-formats' )) {
   echo 'MOV' ;
} else {
   echo '';
}