我正在尝试向services
自定义帖子类型。但是,当我将此函数应用于post类过滤器时,它将此函数应用于所有post类型。我的目标是改变布局services
使用CSS类归档页面。
问题是if ( is_singular(\'services\') )
部分或与global $wp_query;
可能会查询每个帖子?任何解决方案都将不胜感激。
完整代码:
add_filter( \'post_class\', \'woo_custom_add_post_classes\', 10);
function woo_custom_add_post_classes ( $classes ) {
if ( is_singular(\'services\') ) { return $classes; }
global $wp_query;
// Get the number of the current post in the loop.
$current_count = $wp_query->current_post + 1;
// Work out whether this post is the last in a row.
$iflast = \'last\';
if ($current_count % 3 == 0 ) { $iflast = \'last\'; } else { $iflast = \'\';}
// Add the classes to the array of CSS classes.
$classes[] = \'service-number-\' . $current_count; // Service number.
$classes[] = \'threecol-one\';
$classes[] = $iflast; // Last in the row or nothing
return $classes;
} // End woo_custom_add_post_classes()