How to create a while loop inside a PHP string?

I create a query using shortcodes ultimate lightbox. But the only way this will work on a regular php page is to save the data as a string. So what I need to do is create my query, but somehow get my results in a row.

Here is what works before I use any php request:

 <?php     
 $my_tabs = "<ul class='easybuttons'>
 <li>[su_lightbox type='inline' src='#lightbox1']AT&amp;T[/su_lightbox]</li>
 <li>[su_lightbox type='inline' src='#lightbox2']Sprint[/su_lightbox]</li>
 <li>[su_lightbox type='inline' src='#lightbox3']T-Mobile[/su_lightbox]</li>
 </ul>";

 echo do_shortcode( $my_tabs );
 ?> 

but I need ATT, Sprint, T-Mobile to be dynamic. Remember that short code will only work if it is inside a line.

So how can I make a while loop inside this line? I tried using the operator, but did not work.

$args = array('post_type' => 'services', 'category_name' =>  $childid, 'order_by' => 'the_title', 'order' => 'ASC');     

 query_posts($args);

// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
 $my_tabs .= '<ul class="easybuttons">'; 
 while ( $the_query->have_posts() ) { 
 $the_query->the_post();
 $my_tabs .= '<li>[su_lightbox type="inline" src="#lightbox1"]' . get_the_title() . '</li>';
 }
$my_tabs .= '</ul>';
}
/* Restore original Post Data */
wp_reset_postdata();

  echo do_shortcode( $my_tabs );
 ?>

UPDATE:

I tried using this code, but it works. Nothing happens. I do not get any errors, but the short code is not displayed.

 <?php 
  $args = array('post_type' => 'services', 'category_name' =>  $childid, 'order_by' => 'the_title', 'order' => 'ASC');   


 // The Query
  $the_query = new WP_Query( $args );

 // The Loop
 if ( $the_query->have_posts() ) {
  $lid = 1;
  $my_tabs .= '<ul class="easybuttons">'; 
  while ( $the_query->have_posts() ) { 
   $the_query->the_post();
   $my_tabs .= '<li>[su_lightbox type="inline" src="#lightbox' . $lid . '"]' . get_the_title() . '</li>';
   $lid++;
  }
 $my_tabs .= '</ul>';
 }

 echo do_shortcode( $my_tabs );
 wp_reset_postdata();   
+4
1

$my_tabs -, , if, . query_posts(). order_by title, the_title. , $childid slug, not , , , , -, , , , .

$args = array('post_type' => 'services', 'category_name' =>  $childid, 'order_by' => 'title', 'order' => 'ASC');

// The Query
$the_query = new WP_Query( $args );

$my_tabs = '';

// The Loop
if ( $the_query->have_posts() ) {
 $lid = 1;
 $my_tabs .= '<ul class="easybuttons">'; 
 while ( $the_query->have_posts() ) { 
  $the_query->the_post();
  $my_tabs .= '<li>[su_lightbox type="inline" src="#lightbox' . $lid . '"]' . get_the_title() . '</li>';
  $lid++;
 }
$my_tabs .= '</ul>';
}
+5

All Articles