admin管理员组文章数量:1330646
$args = array('parent' => 17);
$categories = get_categories( $args );
foreach($categories as $category) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
echo '<p> Description:'. $category->description . '</p>';
echo '<p> Post Count: '. $category->count . '</p>';
}
from the above code i got the subcategories also i want to display images for subcategories with hyperlink and the above code does not show empty category. help me in this.
$args = array('parent' => 17);
$categories = get_categories( $args );
foreach($categories as $category) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
echo '<p> Description:'. $category->description . '</p>';
echo '<p> Post Count: '. $category->count . '</p>';
}
from the above code i got the subcategories also i want to display images for subcategories with hyperlink and the above code does not show empty category. help me in this.
Share Improve this question edited Jul 26, 2020 at 11:46 mozboz 2,6281 gold badge12 silver badges23 bronze badges asked Jul 26, 2020 at 5:54 nareshnaresh 11 Answer
Reset to default 0Wordpress taxonomies (Categories and Tags) do not have featured images, so there is nothing 'standard' that you can use. Therefore you need to customise your code to suit by using Custom Fields to extend the taxonomy to include an image.
However, manually coding this becomes somewhat more complicated when using Images from your media library so you may find it more convenient to use a plugin to create and manage these custom fields for you. In the link above, you will see three plugins listed at the bottom of the page. I only have experience of Advanced Custom Fields but using that plugin I have added Images to Categories and output them as per your example, so its definitely possible. There are plenty of help pages to assist you with this.
As for showing the empty categories, thats simply a case of adding an extra argument to your get_categories function, like this:
$args = array('parent' => 17,'hide_empty' => false);
$categories = get_categories( $args );
本文标签: categoriesshow thumbnail for subcategory wordpress
版权声明:本文标题:categories - show thumbnail for subcategory wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742232099a2437406.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论