get_post_class() public static method

public static get_post_class ( string $post_type, string | array $post_class = '\Timber\Post' ) : string
$post_type string
$post_class string | array
return string
Ejemplo n.º 1
0
 /**
  * @param mixed $query
  * @param string|array $PostClass
  * @return array|bool|null
  */
 public static function get_post($query = false, $PostClass = '\\Timber\\Post')
 {
     // if a post id is passed, grab the post directly
     if (is_numeric($query)) {
         $post_type = get_post_type($query);
         $PostClass = PostGetter::get_post_class($post_type, $PostClass);
         $post = new $PostClass($query);
         // get the latest revision if we're dealing with a preview
         $posts = PostsCollection::maybe_set_preview(array($post));
         if ($post = reset($posts)) {
             return $post;
         }
     }
     $posts = self::get_posts($query, $PostClass);
     if ($post = reset($posts)) {
         return $post;
     }
 }
Ejemplo n.º 2
0
 protected static function init($posts, $post_class)
 {
     $returned_posts = array();
     if (is_null($posts)) {
         $posts = array();
     }
     foreach ($posts as $post_object) {
         $post_type = get_post_type($post_object);
         $post_class_use = PostGetter::get_post_class($post_type, $post_class);
         // Don't create yet another object if $post_object is already of the right type
         if (is_a($post_object, $post_class_use)) {
             $post = $post_object;
         } else {
             $post = new $post_class_use($post_object);
         }
         if (isset($post->ID)) {
             $returned_posts[] = $post;
         }
     }
     return self::maybe_set_preview($returned_posts);
 }
Ejemplo n.º 3
0
 public function __construct($posts = array(), $post_class = '\\Timber\\Post')
 {
     $returned_posts = array();
     if (is_null($posts)) {
         $posts = array();
     }
     foreach ($posts as $post_object) {
         $post_type = get_post_type($post_object);
         $post_class_use = PostGetter::get_post_class($post_type, $post_class);
         // Don't create yet another object if $post_object is already of the right type
         if (is_a($post_object, $post_class_use)) {
             $post = $post_object;
         } else {
             $post = new $post_class_use($post_object);
         }
         if (isset($post->ID)) {
             $returned_posts[] = $post;
         }
     }
     $returned_posts = self::maybe_set_preview($returned_posts);
     parent::__construct($returned_posts, $flags = 0, 'Timber\\PostsIterator');
 }