PHP Класс Timber\Post

Наследование: extends Core, implements Timber\CoreInterface
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$ID string the numeric WordPress id of a post, capitalized to match WP usage
$ImageClass string the name of the class to handle images by default
$PostClass string the name of the class to handle posts by default
$TermClass string the name of the class to handle terms by default
$class string stores the CSS classes for the post (ex: "post post-type-book post-123")
$id string the numeric WordPress id of a post
$object_type string what does this class represent in WordPress terms?
$post_author integer the numeric ID of the a post's author corresponding to the wp_user dtable
$post_content string the raw text of a WP post as stored in the database
$post_date string the raw date string as stored in the WP database, ex: 2014-07-05 18:01:39
$post_excerpt string the raw text of a manual post excerpt as stored in the database
$post_parent integer the numeric ID of a post's parent post
$post_status string the status of a post ("draft", "publish", etc.)
$post_title string the raw text of a post's title as stored in the database
$post_type string the name of the post type, this is the machine name (so "my_custom_post_type" as opposed to "My Custom Post Type")
$representation string what does this class represent in WordPress terms?
$slug string the URL-safe slug, this corresponds to the poorly-named "post_name" in the WP database, ex: "hello-world"

Защищенные свойства (Protected)

Свойство Тип Описание
$__type Timber\PostType
$_content string stores the processed content internally
$_next array stores the results of the next Timber\Post in a set inside an array (in order to manage by-taxonomy)
$_permalink string the returned permalink from WP's get_permalink function
$_prev array stores the results of the previous Timber\Post in a set inside an array (in order to manage by-taxonomy)

Открытые методы

Метод Описание
__construct ( mixed $pid = null ) If you send the constructor nothing it will try to figure out the current post id based on being inside The_Loop
__toString ( ) : string Outputs the title of the post if you do something like

{{post}}

author ( ) : User | null Return the author of a post
authors ( )
categories ( ) : array Get the categoires on a particular post
category ( ) : TimberTerm | null Returns a category attached to a post
children ( string | array $post_type = 'any', string | boolean $childPostClass = false ) : array Returns an array of children on the post as Timber\Posts (or other claass as you define).
comment_form ( array $args = [] ) : string Gets the comment form for use on a single article page
comments ( integer $count, string $order = 'wp', string $type = 'comment', string $status = 'approve', string $CommentClass = 'Timber\Comment' ) : boolean | array Gets the comments on a Timber\Post and returns them as an array of TimberComments (or whatever comment class you set).
content ( integer $page, $len ) : string Gets the actual content of a WP Post, as opposed to post_content this will run the hooks/filters attached to the_content. \This guy will return your posts content with WordPress filters run on it (like for shortcodes and wpautop).
convert ( array $data, string $class ) Finds any WP_Post objects and converts them to Timber\Posts
date ( string $date_format = '' ) : string Get the date to use in your template!
edit_link ( ) : boolean | string Returns the edit URL of a post if the user has access to it
format ( ) : mixed
get_author ( ) : User | null Gets a User object from the author of the post
get_categories ( ) : array Get the categories for a post
get_category ( ) : mixed
get_children ( string $post_type = 'any', boolean | string $childPostClass = false ) : array
get_comment_count ( ) : integer
get_comments ( integer $count, string $order = 'wp', string $type = 'comment', string $status = 'approve', string $CommentClass = 'Timber\Comment' ) : array | mixed Get the comments for a post
get_content ( integer $len, integer $page ) : string Displays the content of the post with filters, shortcodes and wpautop applied
get_date ( string $date_format = '' ) : string
get_edit_url ( ) : boolean | string Get the URL that will edit the current post/object
get_field ( string $field_name ) : mixed
get_format ( ) : mixed
get_image ( string $field ) : TimberImage
get_link ( ) : string get the permalink for a post object In your templates you should use link: Read my post
get_method_values ( ) : array
get_modified_author ( ) : User | null
get_modified_date ( string $date_format = '' ) : string
get_modified_time ( string $time_format = '' ) : string
get_next ( boolean $taxonomy = false ) : TimberPost | boolean Get the next post in WordPress's ordering
get_paged_content ( ) : string
get_pagination ( ) : array Get a data array of pagination so you can navigate to the previous/next for a paginated post
get_parent ( ) : boolean | TimberPost Get the parent post of the post
get_path ( ) : string Get the permalink for a post, but as a relative path For example, where {{post.link}} would return "http://example.org/2015/07/04/my-cool-post" this will return the relative version: "/2015/07/04/my-cool-post"
get_permalink ( ) : string
get_post_id_by_name ( string $post_name ) : integer get_post_id_by_name($post_name)
get_post_type ( ) : Timber\PostType Returns the post_type object with labels and other info
get_prev ( $in_same_term = false ) : TimberPost | boolean Get the next post in WordPress's ordering
get_preview ( integer $len = 50, boolean $force = false, string $readmore = 'Read More', boolean | string $strip = true, string $end = '…' ) : string get a preview of your post, if you have an excerpt it will use that, otherwise it will pull from the post_content.
get_tags ( ) : array Gets an array of tags for you to use
get_terms ( string | array $tax = '', boolean $merge = true, $TermClass = '' ) : array Get the terms associated with the post This goes across all taxonomies by default
get_thumbnail ( ) : Timber\Image | null
get_title ( ) : string Outputs the title with filters applied
has_field ( string $field_name ) : boolean
has_term ( string | integer $term_name_or_id, string $taxonomy = 'all' ) : boolean
import_custom ( integer $pid ) gets the post custom and attaches it to the current object
import_field ( string $field_name )
link ( ) : string get the permalink for a post object
meta ( string $field_name = null ) : mixed
modified_author ( ) : User | null Get the author (WordPress user) who last modified the post
modified_date ( string $date_format = '' ) : string
modified_time ( string $time_format = '' ) : string
name ( ) : string
next ( boolean $in_same_term = false ) : mixed
paged_content ( ) : string
pagination ( ) : array Get a data array of pagination so you can navigate to the previous/next for a paginated post
parent ( ) : boolean | Timber\Post Gets the parent (if one exists) from a post as a Timber\Post object (or whatever is set in Timber\Post::$PostClass)
password_required ( ) : boolean whether post requires password and correct password has been provided
path ( ) : string Gets the relative path of a WP Post, so while link() will return http://example.org/2015/07/my-cool-post this will return just /2015/07/my-cool-post
permalink ( ) : string
post_class ( string $class = '' ) : string Get the CSS classes for a post. For usage you should use {{post.class}} instead of {{post.post_class}}
prev ( boolean $in_same_term = false ) : mixed Get the previous post in a set
preview ( ) : PostPreview
tags ( ) : array Gets the tags on a post, uses WP's post_tag taxonomy
terms ( string | array $tax = '', boolean $merge = true, $TermClass = '' ) : array Get the terms associated with the post This goes across all taxonomies by default
thumbnail ( ) : TimberImage | null get the featured image as a TimberImage
time ( string $time_format = '' ) : string Get the time to use in your template
title ( ) : string Returns the processed title to be used in templates. This returns the title of the post after WP's filters have run. This is analogous to the_title() in standard WP template tags.
type ( ) : Timber\PostType Returns the post_type object with labels and other info
update ( string $field, mixed $value ) updates the post_meta of the current object with the given value

Защищенные методы

Метод Описание
check_post_id ( integer $pid ) : integer helps you find the post id regardless of whether you send a string or whatever
determine_id ( $pid ) : integer tries to figure out what post you want to get if not explictly defined (or if it is, allows it to be passed through)
get_info ( integer $pid ) : null | object | WP_Pos\WP_Post Used internally by init, etc. to build TimberPost object
get_post_custom ( integer $pid ) : array Used internally to fetch the metadata fields (wp_postmeta table) and attach them to our TimberPost object
get_post_preview_id ( $query )
get_wp_link_page ( integer $i ) : string
init ( integer $pid = false ) Initializes a Post
maybe_show_password_form ( ) : string | void If the Password form is to be shown, show it!
prepare_post_info ( integer $pid ) : WP_Pos\WP_Post takes a mix of integer (post ID), string (post slug), or object to return a WordPress post object from WP's built-in get_post() function

Описание методов

__construct() публичный Метод

If you send the constructor nothing it will try to figure out the current post id based on being inside The_Loop
public __construct ( mixed $pid = null )
$pid mixed

__toString() публичный Метод

Outputs the title of the post if you do something like

{{post}}

public __toString ( ) : string
Результат string

author() публичный Метод

Return the author of a post
public author ( ) : User | null
Результат User | null A User object if found, false if not

authors() публичный Метод

public authors ( )

categories() публичный Метод

Get the categoires on a particular post
public categories ( ) : array
Результат array of TimberTerms

category() публичный Метод

Returns a category attached to a post
public category ( ) : TimberTerm | null
Результат TimberTerm | null

check_post_id() защищенный Метод

helps you find the post id regardless of whether you send a string or whatever
protected check_post_id ( integer $pid ) : integer
$pid integer ;
Результат integer ID number of a post

children() публичный Метод

Returns an array of children on the post as Timber\Posts (or other claass as you define).
public children ( string | array $post_type = 'any', string | boolean $childPostClass = false ) : array
$post_type string | array _optional_ use to find children of a particular post type (attachment vs. page for example). You might want to restrict to certain types of children in case other stuff gets all mucked in there. You can use 'parent' to use the parent's post type or you can pass an array of post types.
$childPostClass string | boolean _optional_ a custom post class (ex: 'MyTimber\Post') to return the objects as. By default (false) it will use Timber\Post::$post_class value.
Результат array

comment_form() публичный Метод

Gets the comment form for use on a single article page
public comment_form ( array $args = [] ) : string
$args array this $args thing is a fucking mess, [fix at some point](http://codex.wordpress.org/Function_Reference/comment_form)
Результат string of HTML for the form

comments() публичный Метод

Gets the comments on a Timber\Post and returns them as an array of TimberComments (or whatever comment class you set).
public comments ( integer $count, string $order = 'wp', string $type = 'comment', string $status = 'approve', string $CommentClass = 'Timber\Comment' ) : boolean | array
$count integer Set the number of comments you want to get. `0` is analogous to "all"
$order string use ordering set in WordPress admin, or a different scheme
$type string For when other plugins use the comments table for their own special purposes, might be set to 'liveblog' or other depending on what's stored in yr comments table
$status string Could be 'pending', etc.
$CommentClass string What class to use when returning Comment objects. As you become a Timber pro, you might find yourself extending TimberComment for your site or app (obviously, totally optional)
Результат boolean | array

content() публичный Метод

Gets the actual content of a WP Post, as opposed to post_content this will run the hooks/filters attached to the_content. \This guy will return your posts content with WordPress filters run on it (like for shortcodes and wpautop).
public content ( integer $page, $len ) : string
$page integer
Результат string

convert() публичный Метод

Finds any WP_Post objects and converts them to Timber\Posts
public convert ( array $data, string $class )
$data array
$class string

date() публичный Метод

Get the date to use in your template!
public date ( string $date_format = '' ) : string
$date_format string
Результат string

determine_id() защищенный Метод

tries to figure out what post you want to get if not explictly defined (or if it is, allows it to be passed through)
protected determine_id ( $pid ) : integer
Результат integer the numberic id we should be using for this post object

format() публичный Метод

public format ( ) : mixed
Результат mixed

get_author() публичный Метод

Gets a User object from the author of the post
См. также: Timber\Post::author
Устаревший: since 1.0
public get_author ( ) : User | null
Результат User | null

get_categories() публичный Метод

Get the categories for a post
См. также: Timber\Post::categories
Устаревший: since 1.0
public get_categories ( ) : array
Результат array of TimberTerms

get_category() публичный Метод

См. также: Timber\Post::category
Устаревший: since 1.0
public get_category ( ) : mixed
Результат mixed

get_children() публичный Метод

См. также: Timber\Post::children
Устаревший: since 1.0
public get_children ( string $post_type = 'any', boolean | string $childPostClass = false ) : array
$post_type string
$childPostClass boolean | string
Результат array

get_comment_count() публичный Метод

public get_comment_count ( ) : integer
Результат integer the number of comments on a post

get_comments() публичный Метод

Get the comments for a post
См. также: Timber\Post::comments
public get_comments ( integer $count, string $order = 'wp', string $type = 'comment', string $status = 'approve', string $CommentClass = 'Timber\Comment' ) : array | mixed
$count integer
$order string
$type string
$status string
$CommentClass string
Результат array | mixed

get_content() публичный Метод

Displays the content of the post with filters, shortcodes and wpautop applied
public get_content ( integer $len, integer $page ) : string
$len integer
$page integer
Результат string

get_date() публичный Метод

См. также: Timber\Post::date
Устаревший: since 1.0
public get_date ( string $date_format = '' ) : string
$date_format string
Результат string

get_edit_url() публичный Метод

Get the URL that will edit the current post/object
См. также: Timber\Post::edit_link
Устаревший: since 1.0
public get_edit_url ( ) : boolean | string
Результат boolean | string

get_field() публичный Метод

public get_field ( string $field_name ) : mixed
$field_name string
Результат mixed

get_format() публичный Метод

Устаревший: since 1.0
public get_format ( ) : mixed
Результат mixed

get_image() публичный Метод

public get_image ( string $field ) : TimberImage
$field string
Результат TimberImage

get_info() защищенный Метод

Used internally by init, etc. to build TimberPost object
protected get_info ( integer $pid ) : null | object | WP_Pos\WP_Post
$pid integer
Результат null | object | WP_Pos\WP_Post

get_method_values() публичный Метод

public get_method_values ( ) : array
Результат array

get_modified_author() публичный Метод

Устаревший: since 1.0
public get_modified_author ( ) : User | null
Результат User | null

get_modified_date() публичный Метод

См. также: Timber\Post::modified_date
Устаревший: since 1.0
public get_modified_date ( string $date_format = '' ) : string
$date_format string
Результат string

get_modified_time() публичный Метод

public get_modified_time ( string $time_format = '' ) : string
$time_format string
Результат string

get_next() публичный Метод

Get the next post in WordPress's ordering
Устаревший: since 1.0
public get_next ( boolean $taxonomy = false ) : TimberPost | boolean
$taxonomy boolean
Результат TimberPost | boolean

get_paged_content() публичный Метод

public get_paged_content ( ) : string
Результат string

get_pagination() публичный Метод

Get a data array of pagination so you can navigate to the previous/next for a paginated post
Устаревший: since 1.0
public get_pagination ( ) : array
Результат array

get_parent() публичный Метод

Get the parent post of the post
Устаревший: since 1.0
public get_parent ( ) : boolean | TimberPost
Результат boolean | TimberPost

get_path() публичный Метод

Get the permalink for a post, but as a relative path For example, where {{post.link}} would return "http://example.org/2015/07/04/my-cool-post" this will return the relative version: "/2015/07/04/my-cool-post"
Устаревший: since 1.0
public get_path ( ) : string
Результат string

get_post_custom() защищенный Метод

Used internally to fetch the metadata fields (wp_postmeta table) and attach them to our TimberPost object
protected get_post_custom ( integer $pid ) : array
$pid integer
Результат array

get_post_id_by_name() публичный статический Метод

get_post_id_by_name($post_name)
public static get_post_id_by_name ( string $post_name ) : integer
$post_name string
Результат integer

get_post_preview_id() защищенный Метод

protected get_post_preview_id ( $query )

get_post_type() публичный Метод

Returns the post_type object with labels and other info
Устаревший: since 1.0.4
public get_post_type ( ) : Timber\PostType
Результат Timber\PostType

get_prev() публичный Метод

Get the next post in WordPress's ordering
Устаревший: since 1.0
public get_prev ( $in_same_term = false ) : TimberPost | boolean
Результат TimberPost | boolean

get_preview() публичный Метод

If there's a tag it will use that to mark where to pull through.
public get_preview ( integer $len = 50, boolean $force = false, string $readmore = 'Read More', boolean | string $strip = true, string $end = '…' ) : string
$len integer The number of words that WP should use to make the tease. (Isn't this better than [this mess](http://wordpress.org/support/topic/changing-the-default-length-of-the_excerpt-1?replies=14)?). If you've set a post_excerpt on a post, we'll use that for the preview text; otherwise the first X words of the post_content
$force boolean What happens if your custom post excerpt is longer then the length requested? By default (`$force = false`) it will use the full `post_excerpt`. However, you can set this to true to *force* your excerpt to be of the desired length
$readmore string The text you want to use on the 'readmore' link
$strip boolean | string true for default, false for none, string for list of custom attributes
$end string The text to end the preview with (defaults to ...)
Результат string of the post preview

get_tags() публичный Метод

Gets an array of tags for you to use
Устаревший: since 1.0
public get_tags ( ) : array
Результат array

get_terms() публичный Метод

Get the terms associated with the post This goes across all taxonomies by default
Устаревший: since 1.0
public get_terms ( string | array $tax = '', boolean $merge = true, $TermClass = '' ) : array
$tax string | array What taxonom(y|ies) to pull from. Defaults to all registered taxonomies for the post type. You can use custom ones, or built-in WordPress taxonomies (category, tag). Timber plays nice and figures out that tag/tags/post_tag are all the same (and categories/category), for custom taxonomies you're on your own.
$merge boolean Should the resulting array be one big one (true)? Or should it be an array of sub-arrays for each taxonomy (false)?
Результат array

get_thumbnail() публичный Метод

См. также: TimberPost::thumbnail
Устаревший: since 1.0
public get_thumbnail ( ) : Timber\Image | null
Результат Timber\Image | null

get_title() публичный Метод

Outputs the title with filters applied
Устаревший: since 1.0
public get_title ( ) : string
Результат string

has_field() публичный Метод

public has_field ( string $field_name ) : boolean
$field_name string
Результат boolean

has_term() публичный Метод

public has_term ( string | integer $term_name_or_id, string $taxonomy = 'all' ) : boolean
$term_name_or_id string | integer
$taxonomy string
Результат boolean

import_custom() публичный Метод

gets the post custom and attaches it to the current object
public import_custom ( integer $pid )
$pid integer a post ID number

import_field() публичный Метод

public import_field ( string $field_name )
$field_name string

init() защищенный Метод

Initializes a Post
protected init ( integer $pid = false )
$pid integer

maybe_show_password_form() защищенный Метод

If the Password form is to be shown, show it!
protected maybe_show_password_form ( ) : string | void
Результат string | void

meta() публичный Метод

public meta ( string $field_name = null ) : mixed
$field_name string
Результат mixed

modified_author() публичный Метод

Get the author (WordPress user) who last modified the post
public modified_author ( ) : User | null
Результат User | null A User object if found, false if not

modified_date() публичный Метод

public modified_date ( string $date_format = '' ) : string
$date_format string
Результат string

modified_time() публичный Метод

public modified_time ( string $time_format = '' ) : string
$time_format string
Результат string

name() публичный Метод

public name ( ) : string
Результат string

next() публичный Метод

public next ( boolean $in_same_term = false ) : mixed
$in_same_term boolean
Результат mixed

paged_content() публичный Метод

public paged_content ( ) : string
Результат string

pagination() публичный Метод

Get a data array of pagination so you can navigate to the previous/next for a paginated post
public pagination ( ) : array
Результат array

parent() публичный Метод

Gets the parent (if one exists) from a post as a Timber\Post object (or whatever is set in Timber\Post::$PostClass)
public parent ( ) : boolean | Timber\Post
Результат boolean | Timber\Post

password_required() публичный Метод

whether post requires password and correct password has been provided
public password_required ( ) : boolean
Результат boolean

path() публичный Метод

Gets the relative path of a WP Post, so while link() will return http://example.org/2015/07/my-cool-post this will return just /2015/07/my-cool-post
public path ( ) : string
Результат string

post_class() публичный Метод

Get the CSS classes for a post. For usage you should use {{post.class}} instead of {{post.post_class}}
См. также: Timber\Post::$class
public post_class ( string $class = '' ) : string
$class string additional classes you want to add
Результат string a space-seperated list of classes

prepare_post_info() защищенный Метод

takes a mix of integer (post ID), string (post slug), or object to return a WordPress post object from WP's built-in get_post() function
protected prepare_post_info ( integer $pid ) : WP_Pos\WP_Post
$pid integer
Результат WP_Pos\WP_Post on success

prev() публичный Метод

Get the previous post in a set
public prev ( boolean $in_same_term = false ) : mixed
$in_same_term boolean
Результат mixed

preview() публичный Метод

public preview ( ) : PostPreview
Результат PostPreview

tags() публичный Метод

Gets the tags on a post, uses WP's post_tag taxonomy
public tags ( ) : array
Результат array

terms() публичный Метод

Get the terms associated with the post This goes across all taxonomies by default
public terms ( string | array $tax = '', boolean $merge = true, $TermClass = '' ) : array
$tax string | array What taxonom(y|ies) to pull from. Defaults to all registered taxonomies for the post type. You can use custom ones, or built-in WordPress taxonomies (category, tag). Timber plays nice and figures out that tag/tags/post_tag are all the same (and categories/category), for custom taxonomies you're on your own.
$merge boolean Should the resulting array be one big one (true)? Or should it be an array of sub-arrays for each taxonomy (false)?
Результат array

thumbnail() публичный Метод

get the featured image as a TimberImage
public thumbnail ( ) : TimberImage | null
Результат TimberImage | null of your thumbnail

time() публичный Метод

Get the time to use in your template
public time ( string $time_format = '' ) : string
$time_format string
Результат string

title() публичный Метод

Returns the processed title to be used in templates. This returns the title of the post after WP's filters have run. This is analogous to the_title() in standard WP template tags.
public title ( ) : string
Результат string

type() публичный Метод

Returns the post_type object with labels and other info
С версии: 1.0.4
public type ( ) : Timber\PostType
Результат Timber\PostType

update() публичный Метод

updates the post_meta of the current object with the given value
public update ( string $field, mixed $value )
$field string
$value mixed

Описание свойств

$ID публичное свойство

the numeric WordPress id of a post, capitalized to match WP usage
public string $ID
Результат string

$ImageClass публичное свойство

the name of the class to handle images by default
public string $ImageClass
Результат string

$PostClass публичное свойство

the name of the class to handle posts by default
public string $PostClass
Результат string

$TermClass публичное свойство

the name of the class to handle terms by default
public string $TermClass
Результат string

$__type защищенное свойство

protected PostType,Timber $__type
Результат Timber\PostType

$_content защищенное свойство

stores the processed content internally
protected string $_content
Результат string

$_next защищенное свойство

stores the results of the next Timber\Post in a set inside an array (in order to manage by-taxonomy)
protected array $_next
Результат array

$_prev защищенное свойство

stores the results of the previous Timber\Post in a set inside an array (in order to manage by-taxonomy)
protected array $_prev
Результат array

$class публичное свойство

stores the CSS classes for the post (ex: "post post-type-book post-123")
public string $class
Результат string

$id публичное свойство

the numeric WordPress id of a post
public string $id
Результат string

$object_type публичное свойство

what does this class represent in WordPress terms?
public string $object_type
Результат string

$post_author публичное свойство

the numeric ID of the a post's author corresponding to the wp_user dtable
public int $post_author
Результат integer

$post_content публичное свойство

the raw text of a WP post as stored in the database
public string $post_content
Результат string

$post_date публичное свойство

the raw date string as stored in the WP database, ex: 2014-07-05 18:01:39
public string $post_date
Результат string

$post_excerpt публичное свойство

the raw text of a manual post excerpt as stored in the database
public string $post_excerpt
Результат string

$post_parent публичное свойство

the numeric ID of a post's parent post
public int $post_parent
Результат integer

$post_status публичное свойство

the status of a post ("draft", "publish", etc.)
public string $post_status
Результат string

$post_title публичное свойство

the raw text of a post's title as stored in the database
public string $post_title
Результат string

$post_type публичное свойство

the name of the post type, this is the machine name (so "my_custom_post_type" as opposed to "My Custom Post Type")
public string $post_type
Результат string

$representation публичное статическое свойство

what does this class represent in WordPress terms?
public static string $representation
Результат string

$slug публичное свойство

the URL-safe slug, this corresponds to the poorly-named "post_name" in the WP database, ex: "hello-world"
public string $slug
Результат string