Forums

Custom Field Template
hide if field is empty (11 posts)

  1. aptharsia
    Member
    Posted 10 months ago #

    Right now I'm using the shortcode format to output the data in a post, in combo with the GT Tabs plugin. I'm doing it this way so I can put different fields in multiple tabs. I'm thinking there has to be a way to do this just with the template, instead of the way I'm doing it.

    title--->Status: Active <---the value
    example

    This is the shortcode format I'm using:
    <span class="status">Status: </span>[listed]<br>

    And just to clarify what I'm entering in the edit post page I'm using these shortcodes, to work with the GT Tabs:

    [tab: Property Info]
    [cft format=0]
    [tab: Broker & MLS]
    [cft format=1]
    [tab: Maps]
    [cft key=maps]
    [tab:END]

    Now, when I don't want to have the Status shown, since I've got the word 'Status' to show even if I don't have the field, filled in, how do I get the word 'Status' to disappear? (You can see the value for 'Bath' is empty but the word 'Bath' still appears in the link example.) I know it's because I've got it written into the format, but is there an option I've missed that I can use in the template to display the title automatically instead of having to write it in the shortcode format like I am?

  2. s_ha_dum (was apljdi)
    Member
    Posted 10 months ago #

    I know I could do it by editing the plugin but I don't know if this is already built into the plugin. I didn't see anything in the plugin's description that really stood out-- maybe the 'blank' option. I'm not sure. Sorry. If you feel adventurous I could get you started on editing that :)

  3. aptharsia
    Member
    Posted 10 months ago #

    Call me Indiana, I'd love some help with this. I don't know what the blank option does. Is there documentation on all the options?

  4. s_ha_dum (was apljdi)
    Member
    Posted 10 months ago #

    Look in the plugin's folder and find the add_shortcode function, then look at the second parameter. Find the function with that parameter's name. You will want to add something like this to the top of that function:

    if (empty(<somevalue>)) {
        return false;
    }

    I say '<somevalue>' because I don't know how the plugin has things named. Basically, you want to find the 'content', see if it is empty, and return nothing if it is. I'd have to download the plugin at look at it to do better. Let me know if you need more help.

  5. aptharsia
    Member
    Posted 10 months ago #

    if ( function_exists('add_shortcode') ) :
    			add_shortcode( 'cft', array(&$this, 'output_custom_field_values') );
    			add_shortcode( 'cftsearch', array(&$this, 'search_custom_field_values') );
    		endif;
    	}

    Of course, I'm lost. This is what the add_shortcode looks like. You said look at the second parameter, I'm not sure what that means I need to look for.

  6. s_ha_dum (was apljdi)
    Member
    Posted 10 months ago #

    This is the second parameter for the first add_shortcode-- array(&$this, 'output_custom_field_values')-- and for the second-- array(&$this, 'search_custom_field_values'). That array syntax is how you pass callbacks from inside an object so don't feel bad about being lost. The part you want is the second array value- 'output_custom_field_values' and 'search_custom_field_values'. Based on the names, I'd say you don't need to mess with the second one. Look for function output_custom_field_values.

  7. aptharsia
    Member
    Posted 10 months ago #

    This is way more over my head than I thought it would be.

    What I call the title is called the label in the plugin. So maybe instead there is something I can add or edit to make the label show on the post page, because that's basically what I'm looking for it to do.

  8. s_ha_dum (was apljdi)
    Member
    Posted 10 months ago #

    This is way more over my head than I thought it would be.

    Oh come on... its fun!!!

    However, now I don't understand what you want to do. What you are now saying seems to contradict what you started out wanting to do. ???

  9. aptharsia
    Member
    Posted 10 months ago #

    No, it's the same, sorry if it's confusing, mostly because I'm confused as to what all the terms are called. :)

    Since I use the same label name as the title I want to display on the posted page, I thought there was an easier way to force the label to also display on the posted page along with the field info.

    Thanks for your help, and sorry about the confusion. :)

  10. s_ha_dum (was apljdi)
    Member
    Posted 10 months ago #

    So all you are trying to do is get the one piece of information that matches the title name?

  11. aptharsia
    Member
    Posted 10 months ago #

    Yes, I have a few different title names I want to show in the post. The title names are the same for the label names (that show in the edit post page for each field), if that makes sense.

    I could just type these title names every time for each post, but I have about 7 for each post, and it just gets tiring after a while. I'm sure there is a way to do this, I just don't know how it could be done.

Reply

You must log in to post.

About this Plugin

About this Topic