Posted By

shin on 09/26/12


Tagged

wordpress wp categories


Versions (?)

show subcategories with picture and description


 / Published in: PHP
 

second level of categories (when offset=-1 doesn't work, like for "getcategorylink()"), pictures must be called exactly like category slug and placed to "catimg" folder. also i used "substr" for cut decription (314 symbols but you can change it). UPDATE: substr() replaced for mbsubstr cause of unicode unknown symbols in cyrilic. UPDATE2: replaced mbsubstr for function (http://snipplr.com/view/67430/cut-string-without-partial-words-unicode-version-with-mbsubstr/), now we have only full words, no partial.

  1. <?php
  2. $query = "SELECT b.name, b.slug, description, b.term_id
  3. FROM $wpdb->term_taxonomy AS a
  4. LEFT JOIN $wpdb->terms AS b ON ( b.term_id = a.term_id)
  5. WHERE a.parent = $cat
  6. AND a.taxonomy = 'category'";
  7. $_ativis = $wpdb->get_results($query, OBJECT);
  8. ?>
  9. <?php foreach ($_ativis as $_ativi) : ?>
  10. <?php
  11. $link = get_category_link($_ativi->term_id);
  12. $excerpt = descr_excerpt($_ativi->description, 180);
  13. ?>
  14. <?php echo '<li><a href="'. $link .'"><img class="podcatsimg" src="catimg/' . $_ativi->slug . '.jpg"><p><span>' . $_ativi->name . '</span></p></a><p>' . strip_tags($excerpt) . '...</p></li>' ?>
  15. <?php endforeach; ?>

Report this snippet  

You need to login to post a comment.