Tag Archives: Category

WordPresss query to fetch the posts under the given categories

<?php
 global $wpdb;
 $const="4,8,7"; //category Ids
 $querystr = "SELECT distinct(wposts.post_title),wposts.ID  FROM $wpdb->posts
 wposts LEFT JOIN $wpdb->term_relationships ON (wposts.ID =
 $wpdb->term_relationships.object_id)
 LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id =
 $wpdb->term_taxonomy.term_taxonomy_id) WHERE $wpdb->term_taxonomy.taxonomy
 = 'category'  AND $wpdb->term_taxonomy.term_id IN($const) ORDER BY rand() ";
 $pageposts = $wpdb->get_results($querystr, OBJECT);
?>

List category and subcategory on sidebar – Magento

<?php
 $obj = new Mage_Catalog_Block_Navigation();
 $store_cats = $obj->getStoreCategories();
 $current_cat = $obj->getCurrentCategory();
 $current_cat = (is_object($current_cat) ? $current_cat->getName() : '');?>
 <?php foreach ($store_cats as $cat)
 { if ($cat->getName() == $current_cat) {
  echo '<li style="padding-left:5px;">
  <a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."
  </a>n<ul>n";
 foreach ($obj->getCurrentChildCategories() as $subcat)
{ echo '<li style="padding-left:15px;">
 <a href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a>
 </li>n"; }
 echo "</ul>n</li>n"; }
else
 { echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."
 </a></li>n"; }}

?>