自定义分类错误的POST类

时间:2014-11-26 作者:Picard102

下面的代码有两个错误。我实际上是在尝试遍历所有自定义分类法,并将它们添加到post类中。

注意:在/Applications/MAMP/htdocs/Dev/wp-includes/taxonomy中进行数组到字符串的转换。php在线3317

注意:在Applications/MAMP/htdocs/Dev/wp includes/category模板中,数组到字符串的转换。第1253行php

if ( ! function_exists(\'custom_taxonomy_class\') ) {

    function custom_taxonomy_class($classes, $class, $ID) {

       $args = array(
         \'public\'   => true,
         \'_builtin\' => false

       ); 
       $output = \'names\'; // or objects
       $operator = \'and\'; // \'and\' or \'or\'

       $taxonomies = get_taxonomies( $args, $output, $operator ); 
       $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[] = \'\';

        return $classes;
    }
}

add_filter( \'post_class\', \'custom_taxonomy_class\', 10, 3 );

1 个回复
SO网友:Picard102

作为一个快速修复,我遍历了每个自定义分类法类型。

if ( ! function_exists(\'custom_taxonomy_class\') ) {

    function custom_taxonomy_class($classes, $class, $ID) {

       $args = array(
         \'public\'   => true,
         \'_builtin\' => false

       ); 
       $output = \'names\'; // or objects
       $operator = \'and\'; // \'and\' or \'or\'
       $taxonomies = get_taxonomies( $args, $output, $operator ); 
       foreach ($taxonomies as $key) {

        $terms = get_the_terms( (int) $ID, $key );

                if ( ! empty( $terms ) ) {
                    foreach ( (array) $terms as $order => $term ) {            
                        if ( ! in_array( $term->slug, $classes ) ) {
                            $classes[] = $term->slug;
                        }
                    }
                }
       }
       $classes[] = \'\';
       return $classes;
    }
}
add_filter( \'post_class\', \'custom_taxonomy_class\', 10, 3 );

结束

相关推荐