开发者 | grzecho |
---|---|
更新时间 | 2019年5月9日 18:29 |
PHP版本: | 3.1 及以上 |
WordPress版本: | 5.2 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
zen_field()
function
<table data-name="some table name">...</table>
Iteration over values in tables
It is possible to iterate over values from your tables. The variable '$zen_fields->tables' holds the array with values from all the tables on the page.
Escaping output
By default output is not escaped which allows you to use links, images and another HTML content in your custom fields. If you would like to escape the output use 'zen_field_esc()' function instead of 'zen_field()'.
For more details check 'Screenshots' section
Simply add table to your page between [zen-fileds] short-tags. And use zen_field()
function to output value from that table.
e.g. <?php echo zen_field(1) ?>
- will output value from second row of your table that contains values only
<?php echo zen_field(1, 2) ?>
- output values from 2 dimensional tables
<?php echo zen_field('field name 2') ?>
- output value from table with key names defined. Key names should be defined in <th>
- table header tags.
<?php echo zen_field('field name 2','column 1') ?>
- output values from 2 dimensional table with key names defined.
Check 'Screenshots' section for more details.
Firstly define the name of each table e.g. <table data-name="some table name">...</table>
, secondly use the table name in the last parameter of zen_field()
function
e.g. <?php echo zen_field('field name 1','column name 2', 'some table name') ?>
The variable $zen_fields->tables
holds an array with values from all the tables on the page. You can use this variable to iterate the data. The way varies depending on table structure. You can output structure of the variable for testing using <pre><?php print_r($zen_fields->tables) ?></pre>
code.
You can submit an issue on GitHub page, where the main repository of the plugin is held. GitHub account is needed. https://github.com/Grzegorzsa/zen-custom-fields/issues
By default output is not escaped which allows you to echo html tags e.g. links or images. If you would like to escape your output use 'zen_field_esc()' instead of 'zen_field()' function.
'zen_field_src()' function can be used to extract link from the image placed in custom field.
<br>
tags in new version of Wordpress<th>
element