Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************************************************
- * a function to recursively build a hierachical category listing;
- * alchymyth 01/2012
- * specialy adapted to work with these accordion scripts:
- * /themes/sztyle/mockup/style.css" />
- * /themes/sztyle/mockup/jquery-1.4.2.min.js"></script>
- * /themes/sztyle/mockup/menu.js"></script>
- *************************************************************************/
- function process_cat_tree( $cat ) {
- global $level; //set depth level
- $args = array(
- 'category__in' => array( $cat ),
- 'numberposts' => -1,
- 'orderby' => 'date', // possible orderby values: 'date', 'title', 'modified', etc - see http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
- 'order' => 'DESC');
- // full query parameter list, see http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
- $cat_posts = get_posts( $args );
- $next = get_categories('hide_empty=0&orderby=slug&parent=' . $cat); //fix for posts in cats with sub cats
- if( $cat_posts ) : //fix for posts in cats with sub cats
- if(!$next) echo "\n ".'<ul class="acitem indent">';//fix for posts in cats with sub cats
- if($next) echo "\n ".'<ul class="menu nestedmenu noaccordion acitem indent">';
- foreach( $cat_posts as $post ) :
- echo "\n ".'<li>';
- //BEGIN post output section//
- $post_thumb = get_the_post_thumbnail($post->ID); //get the post thumbnail - featured image
- $post_link = get_post_meta($post->ID,'_custom_featured_link',true); //get the link url from the custom field
- echo '<div class="postcontent">' . "\n";
- if($post_link) echo '<a href="'. $post_link .'" target="_blank">'; //link tag for post
- if( $post_thumb ) echo $post_thumb . ' '; // code implemented to show thumbnail if exists
- echo $post->post_title; //post title
- if($post_link) echo '</a>'; //close link
- echo apply_filters('the_content',$post->post_content); // in case the post has some content
- echo "\n" . '</div><!--.postcontent-->';
- //END post output section//
- echo "\n ".'</li>';
- endforeach;
- if(!$next) echo "\n ".'</ul><!--/.acitem indent-->';//fix for posts in cats with sub cats
- endif; // end of if( $cat_posts ) :
- $next = get_categories('hide_empty=0&parent=' . $cat);
- $count = 0;
- if( $next ) :
- $level++; //increase depth level
- if($level == 2) echo "\n".'<ul class="menu noaccordion">';
- if(!$cat_posts && $level > 2) echo "\n ".'<ul class="menu nestedmenu noaccordion acitem indent">'; //fix for posts in cats with sub cats
- $cat_posts = ''; //fix for posts in cats with sub cats
- foreach( $next as $cat ) :
- $count++;
- if($level == 2) echo "\n".'<li>';
- if($level > 2) echo "\n ".'<li>';
- echo "\n".'<a href="#" class="level'. ($level-1) .'">'. $cat->name .'</a>';
- process_cat_tree( $cat->term_id );
- if($level == 2) echo "\n".'</li>';
- if($level > 2) echo "\n ".'</li>';
- endforeach;
- $level--; //decrease depth level
- if($level == 1) echo "\n".'</ul><!--/.menu noaccordion-->';
- if($level > 1) echo "\n ".'</ul><!--/.menu nestedmenu noaccordion acitem indent-->';
- endif; //end of if( $next )
- }
- //END OF function process_cat_tree( $cat )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement