Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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 检查是否有使用特定帖子格式撰写的帖子_Php_Wordpress_Wordpress Theming - Fatal编程技术网

Php 检查是否有使用特定帖子格式撰写的帖子

Php 检查是否有使用特定帖子格式撰写的帖子,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我正在构建一个wordpress主题,我需要检查是否有任何帖子是以特定的帖子格式编写的 if ( current_theme_supports( 'post-formats' ) ){ $post_formats = get_theme_support( 'post-formats' ); if ( is_array( $post_formats[0] ) ) { foreach ($post_formats[0] as $post_format) {

我正在构建一个wordpress主题,我需要检查是否有任何帖子是以特定的帖子格式编写的

if ( current_theme_supports( 'post-formats' ) ){
    $post_formats = get_theme_support( 'post-formats' );
    if ( is_array( $post_formats[0] ) ) {
        foreach ($post_formats[0]  as $post_format) { 
            echo '<a href="#">'.$post_format.'</a>'; 
        }
    }
}
这就是我的functions.php中的内容

add_theme_support( 'post-formats', array( 'image', 'link', 'quote', 'status', 'video', 'audio', 'gallery' ) );
还有页面模板文件中的这段代码

if ( current_theme_supports( 'post-formats' ) ){
    $post_formats = get_theme_support( 'post-formats' );
    if ( is_array( $post_formats[0] ) ) {
        foreach ($post_formats[0]  as $post_format) { 
            echo '<a href="#">'.$post_format.'</a>'; 
        }
    }
}
if(当前主题支持('post formats')){
$post_formats=获取主题支持(“post formats”);
if(is_数组($post_格式[0])){
foreach($post_格式[0]作为$post_格式){
回声';
}
}
}
因此,目前我有所有帖子格式显示为链接。我需要的是只显示那些已分配了该帖子格式的帖子

示例:

如果没有指定帖子格式Quote的帖子,则不显示Quote链接

我试着在网上搜索,但没有成功。有人知道如何做到这一点吗?谢谢大家!

$terms=get_terms(“post_格式”);
$terms = get_terms("post_format");
             $count = count($terms);
             if ( $count > 0 ){
                 echo '<ul class="list-group">';
                 foreach ( $terms as $term ) {
                  if($term->count > 0)
                    echo '<a href="#">'.$term->name.'</a>'; 
                 }
                 echo '</ul>';
             }
$count=count($terms); 如果($count>0){ echo'
    ; foreach($terms作为$term){ 如果($term->count>0) 回声'; } 回声“
”; }

试试这个

正是我需要的!非常感谢@wordpresser!!它就像一个符咒!对不起,我没有足够的声誉投票支持你的答案,但我把它标记为接受。哈哈,没问题。。我很高兴这有帮助<代码>post格式也是分类法:D