Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

bibbli on "output of post classes using apply_filters"

$
0
0

I added this to my functions.php to show custom taxonomies as post classes:

add_filter( 'post_class', 'custom_taxonomy_post_class', 10, 3 );

    if ( ! function_exists('custom_taxonomy_post_class') ) {
    function custom_taxonomy_post_class($classes, $class, $ID) {

        $taxonomies_args = array(
            'public' => true,
            '_builtin' => false,
        );

        $taxonomies = get_taxonomies( $taxonomies_args, 'names', 'and' );

        $terms = get_the_terms( (int) $ID, (array) $taxonomies );

        if ( ! empty( $terms ) ) {
            foreach ( (array) $terms as $order => $term ) {
                if ( ! in_array( $term->slug, $classes ) ) {
                    $classes[] = $term->slug;
                }
            }
        }

        $classes[] = 'clearfix';

        return $classes;
    }
    }

I'm trying to output the resulting post classes using 'post_class' but I only get array=" " in the output. Any help would be appreciated.

function start_el(&$output, $page, $depth = 0, $args = array(), $id = 0) {
            if ( $depth )
                $indent = str_repeat("\t", $depth);
            else
                $indent = '';

            extract($args, EXTR_SKIP);

            $output .= $indent . '<li id="item_'.$page->ID.'" '.apply_filters( 'post_class', $page->post_class ).'><span>'.apply_filters( 'the_title', $page->post_title, $page->ID ).'</span>';
        }

Viewing all articles
Browse latest Browse all 8245

Trending Articles