Difference between revisions of "How to customize the layout of custom fields in Theme files"
(→Outputting a certain field group) |
m (group name is used instead of title) |
||
Line 58: | Line 58: | ||
<source lang="php"> | <source lang="php"> | ||
− | <?php echo $CustomFields->displayAll($listing,'content',' | + | <?php echo $CustomFields->displayAll($listing,'content','group-name');?> |
</source> | </source> |
Revision as of 10:28, 27 April 2011
Contents
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.
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/listings_blogview.thtml
- /listings/listings_tableview.thtml
- /listings/listings_thumbview.thtml
- /modules/listings.thtml
Outputting a certain custom field
Outputs the field label
<?php echo $CustomFields->label('jr_fieldname',$listing); ?>
Outputs the field value
<?php echo $CustomFields->field('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_brand',$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_brand',$listing,false,false); ?>
Outputting a certain field group
Outputs a whole field group using the default output.
Just enter the correct Group Title. You can use this to put different groups in different tabs when combined with a tabs plugin.
In JReviews 2.3+
<?php echo $CustomFields->displayAll($listing,'content','group-name');?>
In JReviews 2.2-
<?php echo $this->element('custom_fields',array('entry'=>$listing,'group_name'=>'Group Name','page'=>'content','divWidth'=>'style="width:55%;"')); ?>
Review custom fields
You can place review custom fields in these files:
- /reviews/reviews.thtml (only for user reviews)
- /modules/reviews.thtml
Outputs the field label
<?php echo $CustomFields->label('jr_fieldname',$review); ?>
Outputs the field value
<?php echo $CustomFields->field('jr_fieldname',$review); ?>
In /listings/detail.thtml for the editor review custom fields you can use this code:
Outputs the field label
<?php echo $CustomFields->label('jr_fieldname',$editor_review); ?>
Outputs the field value
<?php echo $CustomFields->field('jr_fieldname',$editor_review); ?>
Custom Field conditionals
Create conditional output based on field's value
<?php if($CustomFields->field('jr_fieldname',$listing,false,false) != ''):?> <!-- Add your code here--> <?php endif;?>