Skip to content
bonsak edited this page Nov 20, 2012 · 1 revision

display()

Return the output for a field. If you want the raw value for use in PHP for custom manipulation, you will want to use field() instead. This function will automatically convert arrays into a list of text such as "Rick, John, and Gary"

public function display ( 
	$name, 
	$single = false 
)

Parameters

Parameter Type Details
$name string or array The field name, or an associative array of parameters
$single boolean (optional) For tableless fields, to return the whole array or the just the first item

Additional Parameter Options

Option Type Default Details
name string $name The field name
orderby string null (optional) For tableless fields, you can choose to return an array of items in a specific order
single bool $single (optional) For tableless fields, to return the whole array or the just the first item
in_form bool false (optional) For internal use. If set to true, always return a full array of data

Returns

(string) or (null) or (false) The output from the field, null if the field doesn't exist, false if no value returned for tablele

Example

<?php
    // We have a "books" Pod with "category" and "the_author" 
    // as single-select relationship fields, related to 
    // "categories" and "authors" Pods
    $params = array(
        'where'   => 't.name LIKE "%rings%"',
        'limit'   => -1  // Return all rows
    );

    // Create and find in one shot
    $books = pods( 'books', $params );

    if ( 0 < $books->total() ) {
        while ( $books->fetch() ) {
?>
        <h2><?php echo $books->display( 'name' ); ?></h2>
        <p>Author: <?php echo $books->display( 'the_author' ); ?></p>
        <br />
        <p>Category: <?php echo $books->display( 'category' ); ?></p>
        <br />
<?php
        } // end of books loop
    } // end of found books

The above example will output:

<h2>The Lord of the Rings</h2>
<p>Author: J. R. R. Tolkien</p>
<br />
<p>Category: Fiction</p>
<br />

Tutorials and other Resources

Available Since Version

2.0+

Source File

display() is located in /pods/classes/Pods.php

See Also