Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Which li are you referring to? Are you using an output filter? Or have you modified a manager template? [+option+] is used as a placeholder in some cases, but without knowing more about what you’re doing I can’t give a proper answer.

    Thread Starter Ash

    (@ashgotti)

    This is how I have it setup now:
    <?php print_custom_field('services_offered:formatted_list', array('<li class="[+value+]">[+value+]</li>','<ul>[+content+]</ul>') );?>

    I would like to use the stored value for the li class=”[+value+]” and the [+value+] for the actual output if I can.

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    “Actual output” is not a good term since I don’t know what you’re referring to.

    See example 2: https://code.google.com/p/wordpress-custom-content-type-manager/wiki/formatted_list_OutputFilter

    Use the [+key+] placeholder and you should be good.

    Thread Starter Ash

    (@ashgotti)

    Thanks for the help. [+key+] outputs a number for each li but I can work with it I guess.

    Actual output I mean the printing of the options.

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    If you haven’t checked “Store unique keys/values” in your field definition, then the key will always be a number because that’s how PHP stores arrays. If you want to have one value stored in the database and display a different value to your users, check that option in your field definition.

    Thread Starter Ash

    (@ashgotti)

    Thanks for the help. I did check it and completed the fields but the code ended up printing those values, not the formatted values.

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    The front-end will always print the stored values. The manager will distinguish between the visible option and the stored value when it generates the form options. If you need to get info about your field definitions in the front-end, you need to read the info out of your field definition: https://code.google.com/p/wordpress-custom-content-type-manager/wiki/get_custom_field_meta

    I don’t recommend structuring your site that way, but you can do it. I’d recommend storing the simplified values in the database and then doing the translation to human-readable messages in your template.

    Thread Starter Ash

    (@ashgotti)

    So basically there is no [+TAG+] for stored values and for visible options? [+Key+] did not work as the multi-select options didn’t have unique keys, keys were assigned by order. I would like the class to be the stored value and the value that is displayed to be the visible options value.

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    When you store data in a custom field, you always store a raw value: this is a central tenet of data normalization. As I explained, the only place where there is a distinction between a raw value and a nicely-formatted visible option is in the manager. Once the value is stored, it’s always stored raw.

    So on the front-end you can either translate the raw value to something human-readable in your templates via a translation function, or by mapping the stored value back to what you displayed to the admins by reading field definition data via the get_custom_field_meta function.

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    I’m going to mark this as resolved: it’s essentially a formatting issue in your template. I try not to over-engineer a plugin to do stuff like this when it’s more easily handled via PHP. Even if you’ve got an array index number, you can use that to make unique class names in your themes, e.g.

    foreach ($array as $i => $val) {
        print '<li class="xyz'.$i.'">'.$val.'</li>';
    }
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Add unique class to multi-select field options?’ is closed to new replies.