• dmx09

    (@dmx09)


    Hi all, I wondered if anyone can shed some light on a small issue I’m having.

    I’ve got an events page (which just loads posts in 3 different events categories).

    I’m using some conditional statements to control some small graphics that display based on what type of event it is. My questions is, can I use ‘in_category’ to do something only if the particular post is in 2 categories?

    For example:

    <?php
    	if ( in_category( 'new events' AND 'old events' )) {?>

    So if the post is in the ‘New Events’ AND ‘Old Events’ cats, then do something…

    Any thoughts most appreciated!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Michael

    (@alchymyth)

    <?php
    	if ( in_category( 'new events' ) && in_category( 'old events' ) ) {

    ?>

    Thread Starter dmx09

    (@dmx09)

    Hi and many thanks,

    I’ve realised that maybe I’m approaching this incorrectly but not quite sure! This is a rough of what I have, not quite working. I presumed that if I could stipulate the style for posts that were in 2 categories, then it would over-ride the style for posts in single cats – this doesn’t seem to be the case.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Might have a re-think!

    Thread Starter dmx09

    (@dmx09)

    Michael

    (@alchymyth)

    might be a problem with the understanding the if/elseif/else structure:
    https://php.net/manual/en/control-structures.elseif.php

    even if the post is in both categories, the first if statement will be true and the else (with the &&) will not get checked.

    try:
    https://pastebin.com/tm1f9gsC

    depending on the location of that code, you also might need to use the absolute paths to the images

    Thread Starter dmx09

    (@dmx09)

    thanks alchymyth, will give it a go! ??

    Thread Starter dmx09

    (@dmx09)

    As it happened I finally didn’t need to combine styles but thanks for your help! I have another question if anyone has a spare moment!

    I want to give posts different colours depending on which category they are in. I’ve tried this:

    https://pastebin.com/EVhza7mM

    But I get an error (site doesn’t load at all). My php is not good so I’m probably doing something silly here? ??

    Michael

    (@alchymyth)

    remove line 4, 11, and 18; and change (line 23) the <?php endif; ?> to <?php } ?>

    Thread Starter dmx09

    (@dmx09)

    Funnily enough I had tried that earlier this morning but I get the same page error. Here’s my entire page, just in case there is something I missed & if you have time.. many thanks again.

    https://pastebin.com/S5gwjmTm

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Changing style if post is in category 1 AND category 2’ is closed to new replies.