GET_POST_CLASS()不能正常工作

时间:2013-12-28 作者:urok93

我正在使用get\\u post\\u类为我的帖子获取类:

post-75 post类型post状态发布格式标准类别未分类条目三分之一摘要优先

但返回的数组不正确:

array (size=9)
  0 => string \'post-21\' (length=7)
  1 => string \'post\' (length=4)
  2 => string \'type-post\' (length=9)
  3 => string \'status-publish\' (length=14)
  4 => string \'format-standard\' (length=15)
  6 => string \'category-uncategorized\' (length=22)
  7 => string \'entry\' (length=5)
  8 => string \'one-third teaser\' (length=16)
  9 => string \'first\' (length=5)
三分之一和Triser应该在单独的插槽中。

这是从Bill Erickson的Genesis网格循环插件生成类的代码:

/**
 * Grid Loop Post Classes
 *
 * @author Bill Erickson
 * @link http://www.billerickson.net/a-better-and-easier-grid-loop/
 *
 * @param array $classes
 * @return array $classes
 */
function be_grid_loop_post_classes( $classes ) {
    global $wp_query;
    $grid_args = $this->be_grid_loop_pagination();
    if( ! $grid_args )
        return $classes;

    // Convert teaser column to a class
    $teaser_columns = array( \'\', \'\', \'one-half\', \'one-third\', \'one-fourth\', \'one-fifth\', \'one-sixth\' );
    $teaser_column = $teaser_columns[$grid_args[\'teaser_columns\']];

    // First Page Classes
    if( ! $wp_query->query_vars[\'paged\'] ) {

        // Features
        if( $wp_query->current_post < $grid_args[\'features_on_front\'] ) {
            $classes[] = \'feature\';

        // Teasers
        } else {
            $classes[] = $teaser_column . \' teaser\';
            if( 0 == ( $wp_query->current_post - $grid_args[\'features_on_front\'] ) || 0 == ( $wp_query->current_post - $grid_args[\'features_on_front\'] ) % $grid_args[\'teaser_columns\'] )
                $classes[] = \'first\';
        }

    // Inner Pages
    } else {

        // Features
        if( $wp_query->current_post < $grid_args[\'features_inside\'] ) {
            $classes[] = \'feature\';

        // Teasers
        } else {
            $classes[] = $teaser_column . \' teaser\';
            if( 0 == ( $wp_query->current_post - $grid_args[\'features_inside\'] ) || 0 == ( $wp_query->current_post - $grid_args[\'features_inside\'] ) % $grid_args[\'teaser_columns\'] )
                $classes[] = \'first\';
        }

    }

    return $classes;
}

1 个回复
最合适的回答,由SO网友:fuxia 整理而成

您可以使用$classes[] = $teaser_column . \' teaser\';

请使用以下选项:

$classes[] = $teaser_column;
$classes[] = \'teaser\';

结束

相关推荐

WP_Query in functions.php

我有一些代码要转换成函数。它工作得很好,直到我将其包装到所述函数中: $args = array( \'posts_per_page\' => -1, \'post_type\' => \'asset\', \'category_name\' => $cat ); $cat_query = new WP_Query( $args );