miriamdepaula

WordPress: wp_list_categories() Walker to list posts

Mar 17th, 2012
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2. //USAGE:
  3. //wp_list_categories( array( 'title_li' => '', 'echo' => false , 'walker' => new PCWalker() ) ) .
  4.  
  5. class PCWalker extends Walker_Category {
  6.  
  7.   function end_el(&$output, $page, $depth, $args) {
  8.       global $wpdb;
  9.       //$output .= "called with: " . $page->term_id;
  10.       $posts = $wpdb->get_results("select object_id as ID from wp_term_relationships r "
  11.         . "join wp_posts p on r.object_id = p.ID where p.post_status = 'publish' and r.term_taxonomy_id = "
  12.         . "(SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE taxonomy = 'category' and term_id = " . $page->term_id . ")");
  13.       if($posts) :
  14.         $output .= '<ul class="posts">'; foreach($posts as $post) { $output .= '
  15.     <li>'; $output .= '<a title="ver ' . get_the_title($post->ID) . '" href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a>'; $output .= '</li>
  16. '; } $output .= '</ul>
  17. ';
  18.       endif;
  19.       parent::end_el(&$output, $page, $depth, $args);
  20.     }
  21. }
  22.  
  23.  
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment