php中如何写while,如何在PHP字符串中创建while循环?

我正在使用短代码终极灯箱创建查询.但是这在常规php页面中工作的唯一方法是将数据保存为字符串.所以我需要做的是创建我的查询,但不知何故在字符串中得到我的结果.

在使用任何类型的php查询之前,这是有用的:

$my_tabs = "

  • [su_lightbox type='inline' src='#lightbox1']AT&T[/su_lightbox]
  • [su_lightbox type='inline' src='#lightbox2']Sprint[/su_lightbox]
  • [su_lightbox type='inline' src='#lightbox3']T-Mobile[/su_lightbox]
";

echo do_shortcode( $my_tabs );

?>

但我需要ATT,Sprint,T-Mobile才能充满活力.请记住,短代码只有在字符串中才有效.

那我怎么能在这个字符串中做一个while循环呢?我尝试使用运算符但没有工作.

$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 .= '

  • ';

while ( $the_query->have_posts() ) {

$the_query->the_post();

$my_tabs .= '

[su_lightbox type="inline" src="#lightbox1"]' . get_the_title() . '';

}

$my_tabs .= '

';

}

/* Restore original Post Data */

wp_reset_postdata();

echo do_shortcode( $my_tabs );

?>

更新:

我尝试使用此代码但它确实有效.没有任何事情发生.我没有收到任何错误,但没有显示短代码.

$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 .= '

  • ';

while ( $the_query->have_posts() ) {

$the_query->the_post();

$my_tabs .= '

[su_lightbox type="inline" src="#lightbox' . $lid . '"]' . get_the_title() . '';

$lid++;

}

$my_tabs .= '

';

}

echo do_shortcode( $my_tabs );

wp_reset_postdata();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值