Code from existing widget:

$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">
            $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; ?>">

Currently outputs all divs with class="tg-one-third" and one with tg-one-third-last. I need to target them individually to add icon styles. I've searched but struggled to find answers that used the above syntax.

  • What is actually the question? Right now this sounds like "please someone write the code for me" :( Jan 18, 2016 at 19:12
  • I'm a designer who learns code from adapting examples. I couldn't find an example so was stumped. Luckily, Aric has provided one, below, that other peple can refer to in future too.
    – Dub Scrib
    Jan 19, 2016 at 17:48
  • So you found a sucker that wrote the code for you, congrats for that, but the point of this site is to handle wordpress question and not basic php/html/css questions. And no, this very specific type of questions have very little value to other people. Jan 19, 2016 at 18:45
  • Everybody thinks his sarcasm is unique while in truth it is just a daily boring affair over here. We understand that we live in the entitelment age and people just can't be able to stand being denied of anything they want. Jan 20, 2016 at 18:56

1 Answer 1


Not sure I entirely understand what you need - but try changing the else statement to this:

else {
    $service_class = "tg-one-third tg-item-" . $j;

It should add another class to each, i.e. 'tg-item-1', 'tg-item-2', etc. - allowing you to target those specific divs

  • Thanks very much. I knew it was probably something straightforward but I just couldn't find an example with $j in it.
    – Dub Scrib
    Jan 19, 2016 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.