admin管理员组文章数量:1391944
I am using Isotope to filter posts on the fly from my archive pages.
I have a Custom Post Type called "art". On the sidebar, I've created links to yearly archives on my sidebar, i.e. 2014, 2013, 2012... etc.
When I am on a yearly archive page, i.e. /art/2012, I want only the terms which exist for this custom-post-type on this year's archive page to appear.
For example, if I am on the date archive of 2009, I only have drawings, not paintings, so I only want the category "Drawings" to show, as clicking "Paintings" will yield zero results (hence the redundancy).
The code I have currently on my sidebar.php (outside the loop) is a modified version that I found here which simply makes wordpress regurgitate all categories across all post types, which is not what I want:
<ul id="filters" class="menu filter">
<li><a href="#" data-filter="*">All</a></li>
<?php // Verify if tag/cat is used in archive:
$categorys = get_categories(
array(
'type' => 'art',
'exclude' => '1,5',
'hide_empty' => false
)
);
if ($categorys) {
foreach ($categorys as $category) {
echo '<li>';
if($category->count > 0){ // check cat count
echo '<a href="#" data-filter=".category-' . $category->slug . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name . '</a></li>';
} else { // if no posts
}
} // end foreach
} // end if
?>
</ul>
Can anyone help me write a function which will output the terms that only exist for the yearly date archive page of custom post type "Art"? Been googling for days without avail. :(
I am using Isotope to filter posts on the fly from my archive pages.
I have a Custom Post Type called "art". On the sidebar, I've created links to yearly archives on my sidebar, i.e. 2014, 2013, 2012... etc.
When I am on a yearly archive page, i.e. /art/2012, I want only the terms which exist for this custom-post-type on this year's archive page to appear.
For example, if I am on the date archive of 2009, I only have drawings, not paintings, so I only want the category "Drawings" to show, as clicking "Paintings" will yield zero results (hence the redundancy).
The code I have currently on my sidebar.php (outside the loop) is a modified version that I found here which simply makes wordpress regurgitate all categories across all post types, which is not what I want:
<ul id="filters" class="menu filter">
<li><a href="#" data-filter="*">All</a></li>
<?php // Verify if tag/cat is used in archive: https://wordpress.stackexchange/a/31981/32287
$categorys = get_categories(
array(
'type' => 'art',
'exclude' => '1,5',
'hide_empty' => false
)
);
if ($categorys) {
foreach ($categorys as $category) {
echo '<li>';
if($category->count > 0){ // check cat count
echo '<a href="#" data-filter=".category-' . $category->slug . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name . '</a></li>';
} else { // if no posts
}
} // end foreach
} // end if
?>
</ul>
Can anyone help me write a function which will output the terms that only exist for the yearly date archive page of custom post type "Art"? Been googling for days without avail. :(
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Jan 22, 2014 at 8:37 NatalietteNataliette 571 silver badge6 bronze badges1 Answer
Reset to default 0You should be able to use what you have and just wrap it with:
<?php if ( is_year( ) ) { ?> **Your Code** <?php } ?>
And changing 'hide_empty' => false
to 'hide_empty' => 1
should prevent the cats with no posts from showing.
本文标签:
版权声明:本文标题:Conditional statement for if archive page has posts which contain certain taxonomiescategoriestags, show those terms 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744674720a2619041.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论