• Resolved Graham

    (@cybro)


    Can anyone give me a code example to output in my template as a wrapper with two or more custom fields, please?

    e.g

    <?php
    print_custom_field('fax_number:wrapper', '<span class="my_class"><strong>Fax:</strong> <i>[+contentFIELD1+]</i> <b>[+contentFIELD2+]</b>
    </span>');
    ?>

    I have no idea where to add another print_custom_field :s
    Thanks

    Graham

    http://ww.wp.xz.cn/extend/plugins/custom-content-type-manager/

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

    (@fireproofsocks)

    If you’re trying to wrap 2 fields, then you should probably just do this in PHP — it’s easier. Remember: all the template-functions that the CCTM offers (including all of its output filters) are just for convenience. Not one of them is required. So if it’s not convenient to bend it the way you want, then do it with PHP and take advantage of all of its flexibility.

    The problem with wrapping 2 fields is figuring out when you need to trigger the behavior. Only if field1 is not empty? What if field2 is empty? Or field1 is empty, but field 2 is not empty? You have some variations to handle there, but consider the following:

    <?php
    // in a template file far, far away...
    $field1 = get_custom_field('field1');
    $field2 =  get_custom_field('field2');
    if ($field1) {
    ?>
        <span class="my_class">
           <strong>Fax:</strong> <i><?php print $field1; ?></i>
           <b><?php print $field2; ?></b>
        </span>
    <?php
    }
    ?>
    Thread Starter Graham

    (@cybro)

    Excellent! Now to tidy up my templates and learn more PHP in the process.
    Much appreciated and many thanks, fireproofsocks.

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

The topic ‘Two custom fields in wrapper’ is closed to new replies.