Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/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
在Single.php中显示带有说明的post标记(不是所有标记,只有带有说明的post标记)_Php_Wordpress - Fatal编程技术网

在Single.php中显示带有说明的post标记(不是所有标记,只有带有说明的post标记)

在Single.php中显示带有说明的post标记(不是所有标记,只有带有说明的post标记),php,wordpress,Php,Wordpress,我想在single.php中显示带有说明的单个post标记 我对此进行了搜索,最接近的解决方案如下。但这段代码列出了博客的所有标签,并附有说明 $tags = get_tags( array( 'hide_empty' => false ) ); if ($tags) { foreach ($tags as $tag) { if ($tag->description) { echo '<dt><a href="' .

我想在single.php中显示带有说明的单个post标记

我对此进行了搜索,最接近的解决方案如下。但这段代码列出了博客的所有标签,并附有说明

$tags = get_tags( array( 'hide_empty' => false ) );
if ($tags) {
    foreach ($tags as $tag) {
        if ($tag->description) {
            echo '<dt><a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a></dt><dd>' . $tag->description . '</dd>';
        } 
    } 
}
$tags=get_标记(数组('hide_empty'=>false));
如果($tags){
foreach($tags作为$tag){
如果($tag->description){
回显“.$tag->description.”;
} 
} 
}
我只需要列出带有描述的post标签。(应该排除没有说明的post标记。)

例如:

数据库中有4500+标记

200+标记具有说明

$tags = get_tags( array( 'hide_empty' => false ) );
if ($tags) {
    foreach ($tags as $tag) {
        if ($tag->description) {
            echo '<dt><a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a></dt><dd>' . $tag->description . '</dd>';
        } 
    } 
}
在一个示例单篇文章上有7个标签

其中只有4个有描述

$tags = get_tags( array( 'hide_empty' => false ) );
if ($tags) {
    foreach ($tags as $tag) {
        if ($tag->description) {
            echo '<dt><a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a></dt><dd>' . $tag->description . '</dd>';
        } 
    } 
}
结果:


我只需要在single.php中显示4个标记

您可以尝试下面的代码,它将在single.php中工作

<?php

$tags = wp_get_post_tags(get_the_ID());
if ($tags) {
    foreach ($tags as $tag) {
        if ($tag->description) {
            echo '<dt><a href="' . get_tag_link( $tag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a></dt><dd>' . $tag->description . '</dd>';
        } 
    } 
}

?>


这不是我要找的代码。我们需要修改我共享的代码以过滤“仅post标记”?我不明白你为什么要把一些规范放在那里,比如条款4,顺便说一下,条款7。这是只针对特定职位的manuel方法还是什么?谢谢。通过在wp_get_post_tags函数中传递帖子ID,您将只获得与该帖子相关的标签,您可以在single.phpy中使用该标签。您可以使用上面的代码,它将在single.phpOkay中工作。这很好,因此如果您放弃投票,我将不胜感激。:)这对我也有用。谢谢你的建议。