b2evolution b2evolution

  • Sign in
  • Sign up
  • About
  • Downloads
  • Hosting
  • Docs
  • Support
  • Sign in
  • Sign up
  • Manuals Home
  • Latest Updates
 
  1. b2evolution CMS User Manual
  2. Developer Reference
  3. Website Skins/Themes
  4. Displaying Custom Fields in a Template

Displaying Custom Fields in a Template

This page explains how you can use Custom Fields with PHP code in order to display them exactly the way you want inside of your templates. This is especially useful if you want to build custom templates, either generally or for specific item types.

Note: there are other – potentially easier – ways to display custom fields:

  • With a widget: Item Custom Fields Widget
  • From within the post contents, by using Custom Fields Short Tags

Displaying all fields for a post

The fields that contain values for a post will be displayed at the end of that post. This of course requires that the skin includes the proper code to do that. Here is the proper code in case you need to display all custom fields of an Item:

<?php $Item->custom_fields(); ?>

If you want to only display these fields in single mode (when a single post is displayed), use this instead:

  <?php
  		if( $disp == 'single' )
  		{	// Display custom fields
  			$Item->custom_fields();
  		}
  ?>

Possible additional params to custom_fields() are

  • ‘before’,
  • ‘after’
  • ‘field_format’ ( example: <tr><th>$title$:</th><td>$value$</td></tr> ).
  • ‘fields’ (Empty string to display ALL fields, OR fields names separated by comma to display only requested fields in order what you want)

Displaying a specific field

If you want to display a specific custom field of the item you must know the index of the custom field ( the field index can be generated from the field name as it was described above ).

Here is the proper code in case you need to display a specific custom field of an Item:

<?php $Item->custom( array( 'field' => $field_index ) ); ?>

Possible params to $Item->custom() are:

  • common params:
    • ‘before’
    • ‘after’
    • ‘field’ (mandatory)
  • string custom field params:
    • ‘format’
  • numeric custom field params:
    • ‘decimals’
    • ‘dec_point’
    • ‘thousands_sep’

If the given $field_index doesn’t exist or it is not set for the Item, then nothing will be displayed.

Extracting data for advanced uses

Getting a value for further processing

If you don’t want to display, just want to get a value of an Item custom field you can do:

<?php $value = $Item->get_custom_field_value( $field_index, $restrict_type ); ?>

  • $field_index : if it doesn’t exist or it is not set for the Item, $value will be false.
  • $restrict_type : Restrict field by type (double, varchar, html, text, url), false fo all
Created by fplanque • Last edit by fplanque on 2019-02-10 22:59 • •

No feedback yet

On this page

  • Displaying all fields for a post
  • Displaying a specific field
  • Extracting data for advanced uses
  • Getting a value for further processing

Search the Manual

Content Hierarchy

  • b2evolution CMS User Manual
  • User's Guide
  • Installation / Upgrade
  • Front-office Reference
  • Back-office Reference
  • Developer Reference
    • Website Skins/Themes
      • Skin Development Primer
      • Loading additional resources into a skin
      • Where are the skin files?
      • CSS Guidelines
      • Targeted CSS Selectors
      • Introducing evoSkins
      • Modifying evoSkins
      • Creating evoSkins
      • Skin Tags / API
      • Styling widgets
      • Skin Quality Control
      • Using HTML 5 tags
      • Using Custom Item Templates
      • Using bootstrap classes in footers
      • Using Grunt
      • Dev Menu
      • How to add a Google Font (WebFont) ?
      • Custom Fields in a Template
      • Site Skins
    • Email Skins/Themes
    • b2evolution Files
    • Website Integration
    • Plugins
    • Debugging
    • Technical Reference
    • Hacks
    • Credits
    • Development
    • How to... (Customize)
    • Scheduled Tasks Reference
  • Operations Reference
  • Advanced Topics
  • Glossary
  • Archives
b2

This online manual is powered by b2evolution CMS – A complete engine for your website.

About b2evolution

  • What is it?
  • Features
  • Getting Started
  • Screenshots
  • Online demo
  • Testimonials
  • Design philosophy
  • Free & open source
  • Terms of service

Downloads

  • Latest releases
  • Skins
  • Plugins
  • Language packs

About us

  • About us
  • Contact

Webhosting Guide

  • Web hosting blog
  • Best web hosting
  • Cheap web hosting
  • Green web hosting
  • Hosting with SSH
  • VPS hosting
  • Dedicated servers
  • Reseller hosting
  • Int'l: UK / France

Docs & Support

  • Online manual
  • Forums
  • Hire a pro !

Other

  • Adsense
  • Press room
  • Privacy policy

Stay in touch

  • GitHub
  • Twitter
  • Facebook
  • LinkedIn
  • News blog
  • RSS feed
  • Atom feed

Founded & Maintained by François Planque