admin管理员组文章数量:1130349
My plugin template is currently as follows:
if ( $query->have_posts() )
{
?>
<ul id="list-con">
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<li>
<a id="floimg" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php if ( has_post_thumbnail() ) {the_post_thumbnail("mini-me");} ?><span class="flotnm"><?php the_field('fl_name'); ?></span></a>
</li>
<?php
}
?>
</ul>
I need to incorporate a switch statement inside the loop but I can't figure out the php syntax.
<?php $curtype = get_post_type( $post->ID ); switch($curtype){
case "firstcase":
return <li> code as defined above
break;
case "secondcase":
return some other <li> code as defined above
break;
}
?>
My plugin template is currently as follows:
if ( $query->have_posts() )
{
?>
<ul id="list-con">
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<li>
<a id="floimg" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php if ( has_post_thumbnail() ) {the_post_thumbnail("mini-me");} ?><span class="flotnm"><?php the_field('fl_name'); ?></span></a>
</li>
<?php
}
?>
</ul>
I need to incorporate a switch statement inside the loop but I can't figure out the php syntax.
<?php $curtype = get_post_type( $post->ID ); switch($curtype){
case "firstcase":
return <li> code as defined above
break;
case "secondcase":
return some other <li> code as defined above
break;
}
?>
Share
Improve this question
asked Nov 8, 2018 at 10:09
JoaMikaJoaMika
6986 gold badges27 silver badges58 bronze badges
1 Answer
Reset to default 1if ( $query->have_posts() ) : ?>
<ul id="list-con">
<?php
while ($query->have_posts()) :
$query->the_post();
?>
<?php
switch ( get_post_type( $post->ID ) ) {
case "firstcase":
?>
<li>code as defined above</li>
<?php
break;
case "secondcase":
?>
<li>another code as defined above</li>
<?php
break;
}
?>
<?php
endwhile;
?>
</ul>
<?php endif;
My plugin template is currently as follows:
if ( $query->have_posts() )
{
?>
<ul id="list-con">
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<li>
<a id="floimg" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php if ( has_post_thumbnail() ) {the_post_thumbnail("mini-me");} ?><span class="flotnm"><?php the_field('fl_name'); ?></span></a>
</li>
<?php
}
?>
</ul>
I need to incorporate a switch statement inside the loop but I can't figure out the php syntax.
<?php $curtype = get_post_type( $post->ID ); switch($curtype){
case "firstcase":
return <li> code as defined above
break;
case "secondcase":
return some other <li> code as defined above
break;
}
?>
My plugin template is currently as follows:
if ( $query->have_posts() )
{
?>
<ul id="list-con">
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<li>
<a id="floimg" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php if ( has_post_thumbnail() ) {the_post_thumbnail("mini-me");} ?><span class="flotnm"><?php the_field('fl_name'); ?></span></a>
</li>
<?php
}
?>
</ul>
I need to incorporate a switch statement inside the loop but I can't figure out the php syntax.
<?php $curtype = get_post_type( $post->ID ); switch($curtype){
case "firstcase":
return <li> code as defined above
break;
case "secondcase":
return some other <li> code as defined above
break;
}
?>
Share
Improve this question
asked Nov 8, 2018 at 10:09
JoaMikaJoaMika
6986 gold badges27 silver badges58 bronze badges
1 Answer
Reset to default 1if ( $query->have_posts() ) : ?>
<ul id="list-con">
<?php
while ($query->have_posts()) :
$query->the_post();
?>
<?php
switch ( get_post_type( $post->ID ) ) {
case "firstcase":
?>
<li>code as defined above</li>
<?php
break;
case "secondcase":
?>
<li>another code as defined above</li>
<?php
break;
}
?>
<?php
endwhile;
?>
</ul>
<?php endif;
本文标签: functionsTemplate Loopadd switch case php
版权声明:本文标题:functions - Template Loop - add switch case php 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749197678a2331261.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论