现有小部件的代码:
$get_featured_pages = new WP_Query( array(
\'posts_per_page\' => -1,
\'post_type\' => array( \'page\' ),
\'post__in\' => $page_array,
\'orderby\' => \'post__in\'
) );
echo $before_widget; ?>
<div class="services-block clearfix">
<?php
$j = 1;
while( $get_featured_pages->have_posts() ):$get_featured_pages->the_post();
$page_title = get_the_title();
if( $j == 3 ) {
$service_class = "tg-one-third tg-one-third-last";
}
else {
$service_class = "tg-one-third";
}
?>
<div class="<?php echo $service_class; ?>">
当前输出所有div
class="tg-one-third"
还有一个
tg-one-third-last
. 我需要针对他们单独添加图标样式。我已经搜索过了,但很难找到使用上述语法的答案。
最合适的回答,由SO网友:Aric Watson 整理而成
我不确定我完全理解您需要什么,但请尝试将else语句更改为:
else {
$service_class = "tg-one-third tg-item-" . $j;
}
它应该为每个类添加另一个类,即“tg-item-1”、“tg-item-2”等-允许您针对这些特定的div