• Hi thanks for viewing.

    I would like to style posts from each of 3 categories differently.

    I used this code from codex example which works great for two categories but need an elseif for the third. I dont understand php and have messed around with elseif statement here but cant get it to work. Is there any way to get an elseif into this piece of code?

    ‘<?php if ( in_category(‘facilitation’) ) {?>
    <div class=”post-cat-facilitation”>

    <?php } else { ?>
    <div class=”post-cat-illustration”>
    <?php } ?>’

    Many Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try this:

    <?php if ( in_category('facilitation') ) {?>
    <div class="post-cat-facilitation">
    
    <?php } elseif ( in_category('illustration') ) { ?>
    <div class="post-cat-illustration">
    <?php } ?>
    
    <?php } else { ?>
    <div class="post-cat-meow-meow-meow">
    <?php } ?>

    https://php.net/manual/en/control-structures.elseif.php

    BTW, you are using apostrophes, not backticks, to enclose your code. Backticks are usually on the same key as ~, in the upper left-hand corner of your keyboard: https://bit.ly/backtick

    You can also accomplish this purely through CSS, if you are interested.

    Thread Starter frankjkeane

    (@frankjkeane)

    Nice on Kjodle, i’ll give the esleif a go!

    will have a look for backticks… mac keyboard!

    Thanks

    Thread Starter frankjkeane

    (@frankjkeane)

    Ho Kjodle, just realised i have done this before with css in another site! Just get the cat-item number. is that what you were going to suggest?

    the esleif still broke it, need to get my head around php!

    Thanks

    Frank

    just realised i have done this before with css in another site! Just get the cat-item number. is that what you were going to suggest?

    Yes!

    the esleif still broke it

    This might work:

    <?php if ( in_category('facilitation') ) {?>
    <div class="post-cat-facilitation">
    
    <?php } else ( in_category('illustration') ) { ?>
    <div class="post-cat-illustration">
    <?php } ?>
    
    <?php } else { ?>
    <div class="post-cat-meow-meow-meow">
    <?php } ?>

    Then again, it might not.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Style Categories individually’ is closed to new replies.