首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检查是否有以某种邮政格式撰写的帖子

检查是否有以某种邮政格式撰写的帖子
EN

Stack Overflow用户
提问于 2013-10-15 15:05:26
回答 1查看 99关注 0票数 1

我正在构建一个wordpress主题,我需要检查是否有任何文章写在特定的邮政格式

这就是我在我的functions.php中所拥有的

代码语言:javascript
复制
add_theme_support( 'post-formats', array( 'image', 'link', 'quote', 'status', 'video', 'audio', 'gallery' ) );

以及页面模板文件中的这段代码。

代码语言:javascript
复制
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>'; 
        }
    }
}

所以,目前我有所有Post格式的显示为链接。我需要的是只显示----那些带有Post格式的帖子。

示例:

如果没有指定Post格式Quote的帖子,请不要显示报价链接。

我试过搜索网页,但没有成功。有人知道如何做到这一点吗?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-15 16:15:22

代码语言:javascript
复制
$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>';
             }

尝尝这个

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19384654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档