Return to Snippet

Revision: 59723
at September 29, 2012 22:41 by shin


Updated Code
<?php
				$query = "SELECT b.name, b.slug, description, b.term_id
						  FROM $wpdb->term_taxonomy AS a
						  LEFT JOIN $wpdb->terms AS b ON ( b.term_id = a.term_id)
						  WHERE a.parent = $cat
						  AND a.taxonomy = 'category'";
				$_ativis = $wpdb->get_results($query, OBJECT);
				?>
				<?php foreach ($_ativis as $_ativi) : ?>
					<?php 
					$link = get_category_link($_ativi->term_id); 
					$excerpt = descr_excerpt($_ativi->description, 180);
					?>
					<?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>' ?>
				<?php endforeach; ?>

Revision: 59722
at September 29, 2012 22:19 by shin


Updated Code
<?php
				$query = "SELECT b.name, b.slug, description, b.term_id
						  FROM $wpdb->term_taxonomy AS a
						  LEFT JOIN $wpdb->terms AS b ON ( b.term_id = a.term_id)
						  WHERE a.parent = $cat
						  AND a.taxonomy = 'category'";
				$_ativis = $wpdb->get_results($query, OBJECT);
				?>
				<?php foreach ($_ativis as $_ativi) : ?>
					<?php 
					$link = get_category_link($_ativi->term_id); 
					$excerpt = mb_substr($_ativi->description, 0, 170, 'UTF-8');
					?>
					<?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>' ?>
				<?php endforeach; ?>

Revision: 59721
at September 26, 2012 21:56 by shin


Initial Code
<?php
				$query = "SELECT b.name, b.slug, description, b.term_id
						  FROM $wpdb->term_taxonomy AS a
						  LEFT JOIN $wpdb->terms AS b ON ( b.term_id = a.term_id)
						  WHERE a.parent = $cat
						  AND a.taxonomy = 'category'";
				$_ativis = $wpdb->get_results($query, OBJECT);
				?>
				<?php foreach ($_ativis as $_ativi) : ?>
					<?php $link = get_category_link($_ativi->term_id); ?>
					<?php echo '<li><a href="'. $link .'"><img class="podcatsimg" src="catimg/' . $_ativi->slug . '.jpg"><p><span>' . $_ativi->name . '</span></p></a><p>' . substr($_ativi->description, 0, 314) . '...</p></li>' ?>
				<?php endforeach; ?>

Initial URL


Initial Description
second level of categories (when offset=-1 doesn't work, like for "get_category_link()"), 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 mb_substr cause of unicode unknown symbols in cyrilic. UPDATE2: replaced mb_substr for function (http://snipplr.com/view/67430/cut-string-without-partial-words-unicode-version-with-mbsubstr/), now we have only full words, no partial.

Initial Title
show subcategories with picture and description

Initial Tags
wordpress

Initial Language
PHP