Title: Conditional borders
Last modified: August 30, 2016

---

# Conditional borders

 *  [CodeBane](https://wordpress.org/support/users/codebane/)
 * (@codebane)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/conditional-borders/)
 * I would like to add a border to images that pass a specific condition, what would
   be the best way to approach this? (The border does not need to persist after 
   an image is expanded however, it would be a nice feature to have).
 * Ideally, I want to have another condition to determine what colour the border
   is (but that should be pretty straightforward so you can ignore this).
 * If you require any further information, please let me know.
 * Any help would be greatly appreciated.
 * Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/conditional-borders/#post-6345703)
 * Under what conditions should the border appear?
 *  Thread Starter [CodeBane](https://wordpress.org/support/users/codebane/)
 * (@codebane)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/conditional-borders/#post-6345788)
 * Currently I have tags attached to posts and the first condition would be:
 * If this post has tag x then add border.
 * The second condition is:
 * If a certain value is above 1 then set the colour as something else.
 * I can work out how the conditions will function but my PHP/WordPress knowledge
   is fairly limited so a nudge in the right direction would be more than appreciated.
 * Thanks
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/conditional-borders/#post-6345798)
 * as your theme uses `post_class()` in the content.php template, you could use 
   a filter on `'post_class'` to add a tag specific CSS class or a class if the 
   post has a certain tag.
 * [https://codex.wordpress.org/Function_Reference/post_class#Add_Classes_By_Filters](https://codex.wordpress.org/Function_Reference/post_class#Add_Classes_By_Filters)
 * similar with your other condition.
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/conditional-borders/#post-6345802)
 * Your theme uses `body_class()` and `post_class()`, so there are some CSS classes
   you could use:
 *     ```
       .tag-{slug} .entry-content img {
         border: 2px solid orange;
       }
   
       .tag-{slug} .entry-content img {
         border: 2px solid green;
       }
       ```
   
 * where `{slug}` is the name of the tag, with all punctuation removed, spaces converted
   to hyphens, and all letters converted to lowercase.
 * For your second condition, would something like this work:
 *     ```
       <?php
       if ( $certain_value > 1 ) {
         $border_color = "orange";
       else {
         $border_color = "green";
       }
       ?>
   
       <img src="/path/to/image" style="border: 1px solid <?php echo $border_color; ?>">
       ```
   
 *  Thread Starter [CodeBane](https://wordpress.org/support/users/codebane/)
 * (@codebane)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/conditional-borders/#post-6345871)
 * Hey all, sorry for late reply, gmail puts WordPress into social so I don’t get
   the notification meh.
 * Thanks for the assistance, was not expecting such a rapid response.
 * All makes sense, don’t see any reason why it wouldn’t work, will set it up when
   I get home later and let you know the good news.
 * Thanks again, much appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Conditional borders’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/gridsby/1.3.0/screenshot.png)
 * Gridsby
 * [Support Threads](https://wordpress.org/support/theme/gridsby/)
 * [Active Topics](https://wordpress.org/support/theme/gridsby/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/gridsby/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/gridsby/reviews/)

## Tags

 * [border](https://wordpress.org/support/topic-tag/border/)
 * [colour](https://wordpress.org/support/topic-tag/colour/)
 * [conditional](https://wordpress.org/support/topic-tag/conditional/)

 * 5 replies
 * 3 participants
 * Last reply from: [CodeBane](https://wordpress.org/support/users/codebane/)
 * Last activity: [10 years, 10 months ago](https://wordpress.org/support/topic/conditional-borders/#post-6345871)
 * Status: not resolved