admin管理员组文章数量:1130349
Confusing title but using the Types toolset I added the two letter state code (CA, TX, FL, etc...) to each of my 'Store' custom post type. The following query will order all my stores by state code, in desc/asc order:
$state_code = types_render_field("state-code", array());
$args = array(
'post_type' => 'store',
'posts_per_page' => 100,
'orderby' => array( 'ASC' => 'DESC', 'meta_value' => 'ASC' ),
'meta_key' => 'wpcf-state-code',
);
My question: if I have 10 stores in California, is there a way that, before the first store, I print out a heading (in this case, California)? So if i have states in CA, TX, and FL, before my block of stores in CA it'll say 'Califoarnia', before my block of stores in FL it'll say 'Florida', etc...?
And if so, is there a way to add a dynamic class to each heading? Something like <h2 class="<?php echo $state_code; ?>-state">California</h2> which would output ca-state as the class?
Confusing title but using the Types toolset I added the two letter state code (CA, TX, FL, etc...) to each of my 'Store' custom post type. The following query will order all my stores by state code, in desc/asc order:
$state_code = types_render_field("state-code", array());
$args = array(
'post_type' => 'store',
'posts_per_page' => 100,
'orderby' => array( 'ASC' => 'DESC', 'meta_value' => 'ASC' ),
'meta_key' => 'wpcf-state-code',
);
My question: if I have 10 stores in California, is there a way that, before the first store, I print out a heading (in this case, California)? So if i have states in CA, TX, and FL, before my block of stores in CA it'll say 'Califoarnia', before my block of stores in FL it'll say 'Florida', etc...?
And if so, is there a way to add a dynamic class to each heading? Something like <h2 class="<?php echo $state_code; ?>-state">California</h2> which would output ca-state as the class?
1 Answer
Reset to default 0You could try a concept like the following (post your loop and I will improve the model):
$state_group = 'Open Loop';
// start the loop
// if posts then while
$state_code = // lookup this post state code
if ( $state_code != $state_group ){
echo $state_code;
$state_group = $state_code;
}
//end loop
Confusing title but using the Types toolset I added the two letter state code (CA, TX, FL, etc...) to each of my 'Store' custom post type. The following query will order all my stores by state code, in desc/asc order:
$state_code = types_render_field("state-code", array());
$args = array(
'post_type' => 'store',
'posts_per_page' => 100,
'orderby' => array( 'ASC' => 'DESC', 'meta_value' => 'ASC' ),
'meta_key' => 'wpcf-state-code',
);
My question: if I have 10 stores in California, is there a way that, before the first store, I print out a heading (in this case, California)? So if i have states in CA, TX, and FL, before my block of stores in CA it'll say 'Califoarnia', before my block of stores in FL it'll say 'Florida', etc...?
And if so, is there a way to add a dynamic class to each heading? Something like <h2 class="<?php echo $state_code; ?>-state">California</h2> which would output ca-state as the class?
Confusing title but using the Types toolset I added the two letter state code (CA, TX, FL, etc...) to each of my 'Store' custom post type. The following query will order all my stores by state code, in desc/asc order:
$state_code = types_render_field("state-code", array());
$args = array(
'post_type' => 'store',
'posts_per_page' => 100,
'orderby' => array( 'ASC' => 'DESC', 'meta_value' => 'ASC' ),
'meta_key' => 'wpcf-state-code',
);
My question: if I have 10 stores in California, is there a way that, before the first store, I print out a heading (in this case, California)? So if i have states in CA, TX, and FL, before my block of stores in CA it'll say 'Califoarnia', before my block of stores in FL it'll say 'Florida', etc...?
And if so, is there a way to add a dynamic class to each heading? Something like <h2 class="<?php echo $state_code; ?>-state">California</h2> which would output ca-state as the class?
1 Answer
Reset to default 0You could try a concept like the following (post your loop and I will improve the model):
$state_group = 'Open Loop';
// start the loop
// if posts then while
$state_code = // lookup this post state code
if ( $state_code != $state_group ){
echo $state_code;
$state_group = $state_code;
}
//end loop
本文标签: phpWordpress loop add heading before first of type
版权声明:本文标题:php - Wordpress loop add heading before first of type 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749207088a2332745.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论