Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

this might sound stupid to most dudes around, but, I have this code:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php if ( in_category('123') ) { ?>
<div class="pdfbox">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<p>&nbsp;</p>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('pdfs'); ?></a>
</div>
<?php } else { ?>
<div class="pdfbox">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<p>&nbsp;</p>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('pdfs'); ?></a>
</div>
<?php } ?>
<?php endwhile; else: ?>
<?php endif; ?>

The thing is, how to add another category, like if is category 1 then output, HTML, if 2 the next html, if 3, so on so on..

Thanks!

share|improve this question
    
can you clear to us, do you want to check in the category or is the category? You mention in the code 'in_category' but said within your question 'if is category'. –  Rahil Wazir Oct 3 '13 at 21:41

1 Answer 1

up vote 0 down vote accepted

What you might be looking for here is the elseif statement...

<?php if ( in_category('123') ) { ?>
<div class="pdfbox">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<p>&nbsp;</p>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('pdfs'); ?></a>
</div>
<?php } elseif ( in_category('125') ) { ?>
<div class="pdfbox">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<p>&nbsp;</p>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('pdfs'); ?></a>
</div>
<?php } ?> { ?>

Hope that helps.

share|improve this answer
    
Thanks a lot Simon, so, using this approach I can have as many categories as I want, for example: <?php if ( in_category('123') ) { ?> HTML GOES HERE <?php } elseif ( in_category('124') ) { ?> HTML GOES HERE <?php } elseif ( in_category('125') ) { ?> HTML GOES HERE <?php } elseif ( in_category('126') ) { ?> HTML GOES HERE <?php } elseif ( in_category('127') ) { ?> HTML GOES HERE <?php } ?> { ?> –  Arturo Oct 4 '13 at 2:30
    
BTW, is the closing PHP tag ok? seems like something there is throwing me an error but not sure what. –  Arturo Oct 4 '13 at 15:43
    
What's your error bru? –  Simon Oct 4 '13 at 18:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.