Answer the question
In order to leave comments, you need to log in
How to display subcategory images in Wordpress?
I am using the taxonomy images plugin. I'm trying to display subcategories (with image and text) of certain parent categories on the main page of the site, but for some reason the image cannot be displayed, only the name. Is it even possible to display subcategory images with this plugin?
Here's what I currently have:
<?php
$cat_id = get_query_var('cat');
$catlist = get_categories('hide_empty=0&child_of=' . $cat_id);
echo "<ul>";
foreach($catlist as $categories)
{
echo '<h1><a href="' . get_category_link( $categories->term_id ) . '" title="' . sprintf( __( "View all products in %s" ), $categories->name ) . '" ' . '>' . $categories->name.'</a> </h1> ';
echo '<div class="categoryoverview clearfix">';
$terms = apply_filters( 'taxonomy-images-get-terms', '' );
if ( ! empty( $terms ) ) {
foreach( (array) $terms as $term ) {
if($term->term_id == $categories->term_id) {
print '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, '' );
echo '</a>';
}
}
echo '<p>'. $categories->description; echo '</p>';
}
echo '</div>';
}
echo "</ul>";
?>
Answer the question
In order to leave comments, you need to log in
Use DevTools and see where exactly the indents are set. It will be more clear
You either screwed up with the height and width, or you don’t finish something. Please provide a working example on jsfidle or codepen.
Your width is set to 62 pixels. Change it, and get smaller indents between the stars.
the condition does not work for you
. on the main page get_query_var('cat'); will be ""
from the documentation parameter
child_of - Get the child categories (including all nesting levels) of the specified category. The parameter specifies the ID of the parent category (the category whose nested categories you want to show).
it follows that there will be no subcategories in $catlist
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question