Difference between revisions of "How to customize the layout of custom fields in Theme files"

From JReviews Documentation
Jump to: navigation, search
Line 2: Line 2:
  
 
To simplify the initial setup of JReviews, there's a default output of custom fields for both listings and reviews. If you want to customize them, you can unpublish the fields from both list and detail views in the Fields Manager, and place the fields where you want them in the theme files.  
 
To simplify the initial setup of JReviews, there's a default output of custom fields for both listings and reviews. If you want to customize them, you can unpublish the fields from both list and detail views in the Fields Manager, and place the fields where you want them in the theme files.  
 +
 +
Besides using custom code for custom fields in the theme files, it is possible to customize the field output using the [[Using the Banner Field Type|Banner field type]].
  
 
Custom field placement also allows to use fields in javascript code for Google Maps and other scripts you may want to use.
 
Custom field placement also allows to use fields in javascript code for Google Maps and other scripts you may want to use.
 
  
 
== Listing custom fields ==
 
== Listing custom fields ==
Line 10: Line 11:
 
The following code works in these files:
 
The following code works in these files:
 
*/listings/detail.thtml
 
*/listings/detail.thtml
 +
*/listings/detail_compact.thtml
 +
*/listings/detail_tabs.thtml
 
*/listings/listings_blogview.thtml
 
*/listings/listings_blogview.thtml
 +
*/listings/listings_blogview_compact.thtml
 
*/listings/listings_tableview.thtml
 
*/listings/listings_tableview.thtml
 
*/listings/listings_thumbview.thtml
 
*/listings/listings_thumbview.thtml
 +
*/listings/listings_masonry.thtml
 
*/modules/listings.thtml
 
*/modules/listings.thtml
 
+
*/modules/listings_slideshow.thtml
 +
*/modules/listings_vertical.thtml
  
 
=== Outputting a certain custom field ===
 
=== Outputting a certain custom field ===
 +
 +
In all code examples below replace jr_fieldname with the name of the field that you want to output.
  
 
'''Outputs the field label'''  
 
'''Outputs the field label'''  
 +
 +
This code will output the label of the field where you place the code in the theme file:
 +
 
<source lang="php">
 
<source lang="php">
 
<?php echo $CustomFields->label('jr_fieldname',$listing); ?>
 
<?php echo $CustomFields->label('jr_fieldname',$listing); ?>
Line 24: Line 35:
 
   
 
   
  
'''Outputs the field text'''  
+
'''Outputs the field value text'''  
 +
 
 +
This code will output the text of the field value where you place the code in the theme file:
 +
 
 
<source lang="php">
 
<source lang="php">
 
<?php echo $CustomFields->field('jr_fieldname',$listing); ?>
 
<?php echo $CustomFields->field('jr_fieldname',$listing); ?>
 
</source>
 
</source>
 +
  
 
'''Outputs the field value'''  
 
'''Outputs the field value'''  
 +
 +
If you have a custom field with field options, this code will output the value of the field as it is referenced in the database:
 +
 
<source lang="php">
 
<source lang="php">
 
<?php echo $CustomFields->fieldValue('jr_fieldname',$listing); ?>
 
<?php echo $CustomFields->fieldValue('jr_fieldname',$listing); ?>
Line 39: Line 57:
  
 
The example below calls the brand field and turns off click2search and outputreformat advanced options:
 
The example below calls the brand field and turns off click2search and outputreformat advanced options:
 +
 
<source lang="php">
 
<source lang="php">
<?php echo $CustomFields->field('jr_brand',$listing,false,false); ?>
+
<?php echo $CustomFields->field('jr_fieldname',$listing,false,false); ?>
 
</source>
 
</source>
  
Line 49: Line 68:
  
 
<source lang="php">
 
<source lang="php">
<?php echo $CustomFields->fieldText('jr_brand',$listing,false,false); ?>
+
<?php echo $CustomFields->fieldText('jr_fieldname',$listing,false,false); ?>
 
</source>
 
</source>
 
 
An alternative solution is [[Using banner field type for custom field output]].
 
 
  
  
 
=== Outputting a certain field group ===
 
=== Outputting a certain field group ===
 
  
 
'''Outputs a whole field group using the default output:'''
 
'''Outputs a whole field group using the default output:'''
Line 66: Line 80:
 
</source>
 
</source>
  
Just enter the correct Group Title. You can use this to put different groups in different tabs when combined with a tabs plugin.
 
  
 +
Replace group-name with the name of the field group that you want to output. You can use this to put different groups in different tabs when combined with a tabs plugin.
  
 
'''Outputs multiple field groups:'''
 
'''Outputs multiple field groups:'''
Line 80: Line 94:
 
<?php echo  $CustomFields->displayAll($listing,'content', array('excludeGroups' => array('group-name1', 'group-name2')));?>
 
<?php echo  $CustomFields->displayAll($listing,'content', array('excludeGroups' => array('group-name1', 'group-name2')));?>
 
</source>
 
</source>
 
  
  
Line 86: Line 99:
  
 
You can place review custom fields in these files:
 
You can place review custom fields in these files:
*/reviews/reviews.thtml (only for user reviews)
+
*/reviews/review_layout.thtml
 +
*/reviews/review_list_layout.thtml
 
*/modules/reviews.thtml
 
*/modules/reviews.thtml
 
  
 
'''Outputs the field label'''
 
'''Outputs the field label'''
 +
 +
This code will output the text of the field value where you place the code in the theme file:
 +
 
<source lang="php">
 
<source lang="php">
 
<?php echo $CustomFields->label('jr_fieldname',$review); ?>
 
<?php echo $CustomFields->label('jr_fieldname',$review); ?>
Line 96: Line 112:
  
  
'''Outputs the field value '''
+
'''Outputs the field value text'''
 +
 
 +
This code will output the text of the field value where you place the code in the theme file:
 +
 
 
<source lang="php">
 
<source lang="php">
 
<?php echo $CustomFields->field('jr_fieldname',$review); ?>
 
<?php echo $CustomFields->field('jr_fieldname',$review); ?>
Line 102: Line 121:
  
  
In /listings/detail.thtml for the editor review custom fields you can use this code:
+
== Custom Field conditionals ==
  
 +
If you want to output certain code only if the specific custom field isn't empty, you can use this code:
  
'''Outputs the field label'''
 
 
<source lang="php">
 
<source lang="php">
<?php echo $CustomFields->label('jr_fieldname',$editor_review); ?>
+
<?php if($CustomFields->field('jr_fieldname',$listing,false,false) != ''):?>
 +
  <!-- Add your code here-->
 +
<?php endif;?>
 
</source>
 
</source>
  
  
'''Outputs the field value''' 
+
If you want to output certain code only if the specific custom field has a specific value, you can use this code:
<source lang="php">
+
<?php echo $CustomFields->field('jr_fieldname',$editor_review); ?>
+
</source>
+
  
 
 
== Custom Field conditionals ==
 
 
'''Create conditional output based on field's value'''
 
 
<source lang="php">
 
<source lang="php">
<?php if($CustomFields->field('jr_fieldname',$listing,false,false) != ''):?>
+
<?php if($CustomFields->field('jr_fieldname',$listing,false,false) == 'some-value'):?>
 
   <!-- Add your code here-->
 
   <!-- Add your code here-->
 
<?php endif;?>
 
<?php endif;?>
Line 128: Line 141:
  
  
'''Create conditional output for multiple select or checkbox custom fields based on some field value'''
+
If you have a multiple select or checkbox type of custom field and you want to check if it has a specific value, use this code:
 +
 
 
<source lang="php">
 
<source lang="php">
 
<?php if (in_array('some-value', $CustomFields->fieldValue('jr_fieldname',$listing))): ?>
 
<?php if (in_array('some-value', $CustomFields->fieldValue('jr_fieldname',$listing))): ?>

Revision as of 14:39, 6 January 2014

To simplify the initial setup of JReviews, there's a default output of custom fields for both listings and reviews. If you want to customize them, you can unpublish the fields from both list and detail views in the Fields Manager, and place the fields where you want them in the theme files.

Besides using custom code for custom fields in the theme files, it is possible to customize the field output using the Banner field type.

Custom field placement also allows to use fields in javascript code for Google Maps and other scripts you may want to use.

Listing custom fields

The following code works in these files:

  • /listings/detail.thtml
  • /listings/detail_compact.thtml
  • /listings/detail_tabs.thtml
  • /listings/listings_blogview.thtml
  • /listings/listings_blogview_compact.thtml
  • /listings/listings_tableview.thtml
  • /listings/listings_thumbview.thtml
  • /listings/listings_masonry.thtml
  • /modules/listings.thtml
  • /modules/listings_slideshow.thtml
  • /modules/listings_vertical.thtml

Outputting a certain custom field

In all code examples below replace jr_fieldname with the name of the field that you want to output.

Outputs the field label

This code will output the label of the field where you place the code in the theme file:

<?php echo $CustomFields->label('jr_fieldname',$listing); ?>


Outputs the field value text

This code will output the text of the field value where you place the code in the theme file:

<?php echo $CustomFields->field('jr_fieldname',$listing); ?>


Outputs the field value

If you have a custom field with field options, this code will output the value of the field as it is referenced in the database:

<?php echo $CustomFields->fieldValue('jr_fieldname',$listing); ?>

Get field text without click2search or output re-format

You can also have a bit more control of the output by using additional parameters when you call the display method: $CustomFields->field($name, &$element, $click2search = true, $outputReformat = true)

The example below calls the brand field and turns off click2search and outputreformat advanced options:

<?php echo $CustomFields->field('jr_fieldname',$listing,false,false); ?>


Get text of selected option for select list with images

If you have a select field with images associated to options and want to get the field text for the selected option, use this code:

<?php echo $CustomFields->fieldText('jr_fieldname',$listing,false,false); ?>


Outputting a certain field group

Outputs a whole field group using the default output:

<?php echo $CustomFields->displayAll($listing,'content','group-name');?>


Replace group-name with the name of the field group that you want to output. You can use this to put different groups in different tabs when combined with a tabs plugin.

Outputs multiple field groups:

<?php echo $CustomFields->displayAll($listing,'content', array('includeGroups' => array('group-name1', 'group-name2')));?>


Outputs all field groups except specified:

<?php echo  $CustomFields->displayAll($listing,'content', array('excludeGroups' => array('group-name1', 'group-name2')));?>


Review custom fields

You can place review custom fields in these files:

  • /reviews/review_layout.thtml
  • /reviews/review_list_layout.thtml
  • /modules/reviews.thtml

Outputs the field label

This code will output the text of the field value where you place the code in the theme file:

<?php echo $CustomFields->label('jr_fieldname',$review); ?>


Outputs the field value text

This code will output the text of the field value where you place the code in the theme file:

<?php echo $CustomFields->field('jr_fieldname',$review); ?>


Custom Field conditionals

If you want to output certain code only if the specific custom field isn't empty, you can use this code:

<?php if($CustomFields->field('jr_fieldname',$listing,false,false) != ''):?>
  <!-- Add your code here-->
<?php endif;?>


If you want to output certain code only if the specific custom field has a specific value, you can use this code:

<?php if($CustomFields->field('jr_fieldname',$listing,false,false) == 'some-value'):?>
  <!-- Add your code here-->
<?php endif;?>


If you have a multiple select or checkbox type of custom field and you want to check if it has a specific value, use this code:

<?php if (in_array('some-value', $CustomFields->fieldValue('jr_fieldname',$listing))): ?>
  <!-- Add your code here-->
<?php endif; ?>