Advertisement
alchymyth

cats

Jun 26th, 2011
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php  if( is_category() ) : //because this makes only sense in a category archive page
  2. $cats = array();
  3. $cat = get_query_var('cat');
  4. do {
  5. $cats[] = (int)$cat;
  6. $cat = get_category($cat)->category_parent;  
  7. }
  8. while($cat);
  9.  
  10. $args = array(
  11. 'category__and' => $cats,
  12. 'orderby' => 'post_date'
  13. );
  14. $posts = get_posts( $args ); ?>
  15. <ul>
  16.  <?php   foreach($posts as $post) {
  17.    ?>
  18.      <li><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title('')?></a></li>
  19.    <?php } wp_reset_postdata(); ?>
  20. </ul>
  21. <?php endif; //ends: if( is_category() ) ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement