Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当CPT为';在wordpress中是空的_Php_Wordpress_Tags_Custom Post Type - Fatal编程技术网

Php 当CPT为';在wordpress中是空的

Php 当CPT为';在wordpress中是空的,php,wordpress,tags,custom-post-type,Php,Wordpress,Tags,Custom Post Type,对于post,我使用下面的代码在tag div为空时隐藏它: <?php if( get_the_tags() ){ echo '<div class="keywords"><i class="fa fa-tag"></i> KEYWORDS: <a href="#">'; the_tags( ' ', ', '); echo '</a></div>'; } ?> 但

对于post,我使用下面的代码在tag div为空时隐藏它:

<?php
   if( get_the_tags() ){
    echo '<div class="keywords"><i class="fa fa-tag"></i> KEYWORDS: <a href="#">';
      the_tags( ' ', ', ');
    echo '</a></div>';
   }
?>

但现在我有了另一个名为“team”的自定义帖子类型,但我不知道如果div为空,如何隐藏它,因为它调用标记的方式与上面的方式不同……下面是我现在拥有的代码:

<div class="keywords"><i class="fa fa-tag"></i> KEYWORDS: <a href="#"><?php echo get_the_term_list( get_the_ID(), 'team' ) ?> </a></div>
关键字:
好的,我知道了

<?php
  if( get_the_term_list( get_the_ID(), 'xiriblog-tag' ) ){
    echo '<div class="keywords"><i class="fa fa-tag"></i> 關鍵字 <a href="#">';
    echo get_the_term_list( get_the_ID(), 'xiriblog-tag' );
    echo '</a></div>';
   }  ?>

或者,通过使用变量:

<?php
  $term_list = get_the_term_list( get_the_ID(), 'xiriblog-tag' );
  if( $term_list ){
    echo '<div class="keywords"><i class="fa fa-tag"></i> 關鍵字 <a href="#">';
    echo $term_list;
    echo '</a></div>';
   }  ?>


在我看来,你也可以用同样的方法来完成。为什么不呢?谢谢,我不熟悉php代码…我不太理解这些术语…但我也尝试过同样的方法,而且效果很好!!做得好!我不知道<代码> GETHythiTyMyList是一个繁重的函数,它可以进行大量的处理,但是您可以考虑将结果存储在变量中。这样,您只需要执行函数一次,然后就可以检查其值,稍后再返回其值。我冒昧地在你的答案中添加了这个变体。另一个代码段使用了同一函数的两个变体,
get\u the \u tags
the \u tags
。它看起来像是第一个返回一个值,而后一个回显(输出)值本身。因此,也许还有一个名为
the_term_list
的函数,您可以用它来构建这样的解决方案,尽管我个人更喜欢只使用一个函数。非常感谢您为我提供了另一种解决问题的方法!!这对我来说是一个很好的教训