0

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;
    }
   ?>

1 Answer 1

1
if ( $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;

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.