• Resolved paa1605

    (@paa1605)


    Hi folks,

    Im fairly new to php and would like some help. I’m using a plugin that gives users the ability to add custom fields to categories. I have utilised the plugin so that i can add an associated image to each category. I found some code on another forum topic that allowed me to do this and it worked perfectly. However, not all my categories have images and i would like to modify the code so that i have an ‘else’ statement which would make wordpress leave that area on the page blank rather than the current small blue box which appears indicating that there is no image associated. I have tried myself to do this yet to no joy. If anyone could help i would be very grateful. The code is as follows…

    <?php

    $thisCat = $ps_catid;
    $thisCatName = $ps_catname;
    if(function_exists(‘get_terms_meta’)) {
    $screen = get_terms_meta($thisCat, ‘banner’);
    $screen = $screen[0];

    } ?>

    <div id=”HomePanel-thin”>
    <img src=”<?php echo ($screen); ?>” />
    </div>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Can you create a default image and assign it if needed? If so, you might use code like that below. Change this:

    $screen = get_terms_meta($thisCat, 'banner');
    $screen = $screen[0];
    
    } ?>

    to this:

    $screen = get_terms_meta($thisCat, 'banner');
    $screen = $screen[0];
    if (!$screen) $screen = 'images/default.jpg';  
    
    } ?>

    Replace ‘images/default.jpg’ with the path to your default image. Look at what is stored for the ‘banner’ for other categories to find out the format.

    Thread Starter paa1605

    (@paa1605)

    Excellent, thanks! Works a treat!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Help needed with 'else' statement’ is closed to new replies.