PHP Class Timber\Post

Inheritance: extends Core, implements Timber\CoreInterface
Afficher le fichier Open project: timber/timber Class Usage Examples

Méthodes publiques

Свойство Type Description
$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 Properties

Свойство Type Description
$__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)

Méthodes publiques

Méthode Description
__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

Méthodes protégées

Méthode Description
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

Method Details

__construct() public méthode

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() public méthode

Outputs the title of the post if you do something like

{{post}}

public __toString ( ) : string
Résultat string

author() public méthode

Return the author of a post
public author ( ) : User | null
Résultat User | null A User object if found, false if not

authors() public méthode

public authors ( )

categories() public méthode

Get the categoires on a particular post
public categories ( ) : array
Résultat array of TimberTerms

category() public méthode

Returns a category attached to a post
public category ( ) : TimberTerm | null
Résultat TimberTerm | null

check_post_id() protected méthode

helps you find the post id regardless of whether you send a string or whatever
protected check_post_id ( integer $pid ) : integer
$pid integer ;
Résultat integer ID number of a post

children() public méthode

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.
Résultat array

comment_form() public méthode

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)
Résultat string of HTML for the form

comments() public méthode

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)
Résultat boolean | array

content() public méthode

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
Résultat string

convert() public méthode

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

date() public méthode

Get the date to use in your template!
public date ( string $date_format = '' ) : string
$date_format string
Résultat string

determine_id() protected méthode

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
Résultat integer the numberic id we should be using for this post object

format() public méthode

public format ( ) : mixed
Résultat mixed

get_author() public méthode

Gets a User object from the author of the post
See also: Timber\Post::author
Deprecation: since 1.0
public get_author ( ) : User | null
Résultat User | null

get_categories() public méthode

Get the categories for a post
See also: Timber\Post::categories
Deprecation: since 1.0
public get_categories ( ) : array
Résultat array of TimberTerms

get_category() public méthode

See also: Timber\Post::category
Deprecation: since 1.0
public get_category ( ) : mixed
Résultat mixed

get_children() public méthode

See also: Timber\Post::children
Deprecation: since 1.0
public get_children ( string $post_type = 'any', boolean | string $childPostClass = false ) : array
$post_type string
$childPostClass boolean | string
Résultat array

get_comment_count() public méthode

public get_comment_count ( ) : integer
Résultat integer the number of comments on a post

get_comments() public méthode

Get the comments for a post
See also: 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
Résultat array | mixed

get_content() public méthode

Displays the content of the post with filters, shortcodes and wpautop applied
public get_content ( integer $len, integer $page ) : string
$len integer
$page integer
Résultat string

get_date() public méthode

See also: Timber\Post::date
Deprecation: since 1.0
public get_date ( string $date_format = '' ) : string
$date_format string
Résultat string

get_edit_url() public méthode

Get the URL that will edit the current post/object
See also: Timber\Post::edit_link
Deprecation: since 1.0
public get_edit_url ( ) : boolean | string
Résultat boolean | string

get_field() public méthode

public get_field ( string $field_name ) : mixed
$field_name string
Résultat mixed

get_format() public méthode

Deprecation: since 1.0
public get_format ( ) : mixed
Résultat mixed

get_image() public méthode

public get_image ( string $field ) : TimberImage
$field string
Résultat TimberImage

get_info() protected méthode

Used internally by init, etc. to build TimberPost object
protected get_info ( integer $pid ) : null | object | WP_Pos\WP_Post
$pid integer
Résultat null | object | WP_Pos\WP_Post

get_method_values() public méthode

public get_method_values ( ) : array
Résultat array

get_modified_author() public méthode

Deprecation: since 1.0
public get_modified_author ( ) : User | null
Résultat User | null

get_modified_date() public méthode

See also: Timber\Post::modified_date
Deprecation: since 1.0
public get_modified_date ( string $date_format = '' ) : string
$date_format string
Résultat string

get_modified_time() public méthode

public get_modified_time ( string $time_format = '' ) : string
$time_format string
Résultat string

get_next() public méthode

Get the next post in WordPress's ordering
Deprecation: since 1.0
public get_next ( boolean $taxonomy = false ) : TimberPost | boolean
$taxonomy boolean
Résultat TimberPost | boolean

get_paged_content() public méthode

public get_paged_content ( ) : string
Résultat string

get_pagination() public méthode

Get a data array of pagination so you can navigate to the previous/next for a paginated post
Deprecation: since 1.0
public get_pagination ( ) : array
Résultat array

get_parent() public méthode

Get the parent post of the post
Deprecation: since 1.0
public get_parent ( ) : boolean | TimberPost
Résultat boolean | TimberPost

get_path() public méthode

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"
Deprecation: since 1.0
public get_path ( ) : string
Résultat string

get_post_custom() protected méthode

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
Résultat array

get_post_id_by_name() public static méthode

get_post_id_by_name($post_name)
public static get_post_id_by_name ( string $post_name ) : integer
$post_name string
Résultat integer

get_post_preview_id() protected méthode

protected get_post_preview_id ( $query )

get_post_type() public méthode

Returns the post_type object with labels and other info
Deprecation: since 1.0.4
public get_post_type ( ) : Timber\PostType
Résultat Timber\PostType

get_prev() public méthode

Get the next post in WordPress's ordering
Deprecation: since 1.0
public get_prev ( $in_same_term = false ) : TimberPost | boolean
Résultat TimberPost | boolean

get_preview() public méthode

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 ...)
Résultat string of the post preview

get_tags() public méthode

Gets an array of tags for you to use
Deprecation: since 1.0
public get_tags ( ) : array
Résultat array

get_terms() public méthode

Get the terms associated with the post This goes across all taxonomies by default
Deprecation: 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)?
Résultat array

get_thumbnail() public méthode

See also: TimberPost::thumbnail
Deprecation: since 1.0
public get_thumbnail ( ) : Timber\Image | null
Résultat Timber\Image | null

get_title() public méthode

Outputs the title with filters applied
Deprecation: since 1.0
public get_title ( ) : string
Résultat string

has_field() public méthode

public has_field ( string $field_name ) : boolean
$field_name string
Résultat boolean

has_term() public méthode

public has_term ( string | integer $term_name_or_id, string $taxonomy = 'all' ) : boolean
$term_name_or_id string | integer
$taxonomy string
Résultat boolean

import_custom() public méthode

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 méthode

public import_field ( string $field_name )
$field_name string

init() protected méthode

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

maybe_show_password_form() protected méthode

If the Password form is to be shown, show it!
protected maybe_show_password_form ( ) : string | void
Résultat string | void

meta() public méthode

public meta ( string $field_name = null ) : mixed
$field_name string
Résultat mixed

modified_author() public méthode

Get the author (WordPress user) who last modified the post
public modified_author ( ) : User | null
Résultat User | null A User object if found, false if not

modified_date() public méthode

public modified_date ( string $date_format = '' ) : string
$date_format string
Résultat string

modified_time() public méthode

public modified_time ( string $time_format = '' ) : string
$time_format string
Résultat string

name() public méthode

public name ( ) : string
Résultat string

next() public méthode

public next ( boolean $in_same_term = false ) : mixed
$in_same_term boolean
Résultat mixed

paged_content() public méthode

public paged_content ( ) : string
Résultat string

pagination() public méthode

Get a data array of pagination so you can navigate to the previous/next for a paginated post
public pagination ( ) : array
Résultat array

parent() public méthode

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
Résultat boolean | Timber\Post

password_required() public méthode

whether post requires password and correct password has been provided
public password_required ( ) : boolean
Résultat boolean

path() public méthode

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
Résultat string

post_class() public méthode

Get the CSS classes for a post. For usage you should use {{post.class}} instead of {{post.post_class}}
See also: Timber\Post::$class
public post_class ( string $class = '' ) : string
$class string additional classes you want to add
Résultat string a space-seperated list of classes

prepare_post_info() protected méthode

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
Résultat WP_Pos\WP_Post on success

prev() public méthode

Get the previous post in a set
public prev ( boolean $in_same_term = false ) : mixed
$in_same_term boolean
Résultat mixed

preview() public méthode

public preview ( ) : PostPreview
Résultat PostPreview

tags() public méthode

Gets the tags on a post, uses WP's post_tag taxonomy
public tags ( ) : array
Résultat array

terms() public méthode

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)?
Résultat array

thumbnail() public méthode

get the featured image as a TimberImage
public thumbnail ( ) : TimberImage | null
Résultat TimberImage | null of your thumbnail

time() public méthode

Get the time to use in your template
public time ( string $time_format = '' ) : string
$time_format string
Résultat string

title() public méthode

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
Résultat string

type() public méthode

Returns the post_type object with labels and other info
Since: 1.0.4
public type ( ) : Timber\PostType
Résultat Timber\PostType

update() public méthode

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

Property Details

$ID public_oe property

the numeric WordPress id of a post, capitalized to match WP usage
public string $ID
Résultat string

$ImageClass public_oe property

the name of the class to handle images by default
public string $ImageClass
Résultat string

$PostClass public_oe property

the name of the class to handle posts by default
public string $PostClass
Résultat string

$TermClass public_oe property

the name of the class to handle terms by default
public string $TermClass
Résultat string

$__type protected_oe property

protected PostType,Timber $__type
Résultat Timber\PostType

$_content protected_oe property

stores the processed content internally
protected string $_content
Résultat string

$_next protected_oe property

stores the results of the next Timber\Post in a set inside an array (in order to manage by-taxonomy)
protected array $_next
Résultat array

$_prev protected_oe property

stores the results of the previous Timber\Post in a set inside an array (in order to manage by-taxonomy)
protected array $_prev
Résultat array

$class public_oe property

stores the CSS classes for the post (ex: "post post-type-book post-123")
public string $class
Résultat string

$id public_oe property

the numeric WordPress id of a post
public string $id
Résultat string

$object_type public_oe property

what does this class represent in WordPress terms?
public string $object_type
Résultat string

$post_author public_oe property

the numeric ID of the a post's author corresponding to the wp_user dtable
public int $post_author
Résultat integer

$post_content public_oe property

the raw text of a WP post as stored in the database
public string $post_content
Résultat string

$post_date public_oe property

the raw date string as stored in the WP database, ex: 2014-07-05 18:01:39
public string $post_date
Résultat string

$post_excerpt public_oe property

the raw text of a manual post excerpt as stored in the database
public string $post_excerpt
Résultat string

$post_parent public_oe property

the numeric ID of a post's parent post
public int $post_parent
Résultat integer

$post_status public_oe property

the status of a post ("draft", "publish", etc.)
public string $post_status
Résultat string

$post_title public_oe property

the raw text of a post's title as stored in the database
public string $post_title
Résultat string

$post_type public_oe property

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
Résultat string

$representation public_oe static_oe property

what does this class represent in WordPress terms?
public static string $representation
Résultat string

$slug public_oe property

the URL-safe slug, this corresponds to the poorly-named "post_name" in the WP database, ex: "hello-world"
public string $slug
Résultat string