Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts

    PHP conditional based on whether content exists

    I have a set of custom fields created on WordPress. When there is content for a field, I need a certain image displayed. When the field is blank, I need it hidden.

    If there was no condition involved, this would be the HTML:

    <a href="http://This is where my custom field URL goes"><img src="http://imagesource"></a>

    So basically, the PHP condition is:

    IF there is data entered in the custom field
    THEN display a hyperlinked icon (standard .png file) with the target to the custom field
    ELSE do not display anything

    I think this is a fairly easy problem but I'm pretty novice at PHP. Any ideas?

    Thanks for your help!

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    428
    Thanks
    18
    Thanked 26 Times in 26 Posts
    First off, you posted this in the wrong section. This question is PHP related and should be in the PHP section.

    Now to answer your question you will need to provide more information, such as a form that submits data or variables around this. Otherwise, look into the [CODE]$_POST[/ICODE] global variable.

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,930
    Thanks
    6
    Thanked 1,041 Times in 1,014 Posts
    Quote Originally Posted by bswb97 View Post
    So basically, the PHP condition is:

    IF there is data entered in the custom field
    THEN display a hyperlinked icon (standard .png file) with the target to the custom field
    ELSE do not display anything

    I think this is a fairly easy problem but I'm pretty novice at PHP. Any ideas?
    How about you do an internet search and/or consult the Wordpress Codex? It’s all explained there. Or here, or here, or here

  • Users who have thanked VIPStephan for this post:

    bswb97 (05-20-2014)

  • #4
    New Coder
    Join Date
    Mar 2012
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by VIPStephan View Post
    How about you do an internet search and/or consult the Wordpress Codex? It’s all explained there. Or here, or here, or here
    That first link is perfect. Appreciate the tip, thanks!

    And sorry about posting in the wrong forum. My bookmark is the HTML/CSS forum, just went there on instinct!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •