WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] custom fields

[Resolved] custom fields

  • I have this page that lists the titles of all the posts, I want some to be a different colour depending on a custom field, If it’s empty it should remain the same but if the custom field (finished) has a value (any value) I would like the titles of those posts to be gray.

    Is this possible? There might only be one post with the custom field of finished…

    Finding this a little tricky.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Yes it is possible. I give you a sample.

    <?php
     $cust_val = get_post_meta($post->ID, "color", true);
     if($cust_val !=""):
    ?>
       <h2 style="color:<?php echo $cust_val; ?>"><?php the_title() ?></h2>
    <?php else: ?>
       <h2><?php the_title() ?></h2>
    <?php endif; ?>

    thanks
    Chinmoy

    Moderator keesiemeijer

    @keesiemeijer

    You can do it with get post meta
    [edit] aha to slow, use chinmoy29 solutution

    w00t Works a treat thanks so much, I was on the right lines with an if vlue != “” but didn’t know where to put it.

    One more question, It’s working well on one page, but not on another, I’m unsure if it’s to do with the style hierarchy or if it needs !important in the a href style.

    I’m sure I’ll get there eventually like : )

    Moderator keesiemeijer

    @keesiemeijer

    You have to put this code on your theme’s template files where you want this to happen (page.php, index.php, single.php etc..)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] custom fields’ is closed to new replies.
Skip to toolbar