1

基本的に、フィールドに値がある場合は、フィールド (div でラップ) を呼び出す必要があります。フィールドに値がない場合、フィールドまたは div を表示したくありません。私のPHPの知識は悲惨ですが、ここで私が取り組まなければならないものがあります.

カスタム フィールドを ID で呼び出す方法については、次の手順を参照してください。

$cust_1 = $this->fields->getFieldByCaption('Custom Text'); // getFieldByCaption() allow you to get the field by the Caption. This is not the best way to get a field since changing the caption in the back-end will break the reference.
echo '<br />Field ID: ' . $cust_1->getId();

$cust_2 = $this->fields->getFieldById(29);  // getFieldById() is the ideal way of getting a field. The ID can be found at 'Custom Fields' section in Mosets Tree's back-end.
echo '<br />Name: ' . $cust_2->getName();
echo '<br />Has Caption? ' . (($cust_2->hasCaption()) ? 'Yes' : 'No');
echo '<br />Caption: ' . $cust_1->getCaption();
echo '<br />Value: ' . $cust_2->getValue();
echo '<br />Output: ' . $cust_2->getOutput(1);
echo '<hr />';
$this->fields->resetPointer();
while( $this->fields->hasNext() ) {
$field = $this->fields->getField();
echo '<br /><strong>' . $field->getCaption() . '</strong>';
echo ': ';
echo $field->getOutput(1); // getOutput() returns the formatted value of the field. ie: For a youtube video, the youtube player will be loaded
// echo $field->getValue(); // getValue() returns the raw value without additional formatting. ie: When getting value from a Online Video field type, it will return the URL.
$this->fields->next();
}

これが私が取り組んでいるコードであり、上記で詳述したように、必要なことを試して実行するための助けが必要です:

<?php
if( !is_null($this->fields->getFieldById(35)) ) {
$value = $field->getValue();
$hasValue = $field->hasValue();
$field = $this->fields->getField();

if( $hasValue )
{
    echo '<div class="lin" id="lphn">'; { 
    echo $cust_2 = $this->fields->getFieldById(35);
    echo $cust_2->getOutput(1); 
    echo '</div>';
}
else {
    // Print nothing.
}
}

}
?>
4

0 に答える 0