Typecho article use custom fields

Custom fields are given a Typecho article provides customization, custom fields by typecho bloggers can achieve a variety of custom effects, typical application is a custom article title, keywords and description, or Custom Post thumbnail. In addition, typecho custom fields feature set and calls are very simple.

Custom fields relevant code

Field calling code

1
$field = $this->fields->fieldName;

Output Fields

1
$this->fields->fieldName();

Judgment field

1
2
3
4
5
IF (isset ($ this-> fields-> the fieldName)) { 
  echo 'field is present, is:' $ this-> fields-> the fieldName;. 
} the else { 
  echo 'field does not exist'; 
}
Use custom fields

1, edit the article, click on the "Custom Fields" column, input box will pop up, enter the field name to be used in [name] in the field (
be careful not to use Chinese), drop-down box, select the required type (if it is field names are alphabetic characters on the selection, if the integer is an integer number choose, if the decimal fractional number is selected), the input value corresponding to the field name in the field [value], the article to set custom keyword, for example, as follows Figure:

Typecho article use custom fields

If you need to add additional fields from the field, click Add [+] button to continue to add, such as adding a description

Typecho article use custom fields

2, add custom fields completed, after publishing the article can use the following code to call the set of custom fields:

Direct output custom field values:

1
2
$this->fields->keywords();
$this->fields->description();

The custom field value to the variable specified

1
2
$field = $this->fields->keywords;
$field = $this->fields->description;

The Custom Fields Field Name the above code change the settings of their own name.

Guess you like

Origin www.cnblogs.com/wnh678/p/11872871.html