Ejemplo n.º 1
0
 /**
  * @param mixed a value to test against
  * @return int the numberic id we should be using for this post object
  */
 protected function determine_id($pid)
 {
     global $wp_query;
     if ($pid === null && isset($wp_query->queried_object_id) && $wp_query->queried_object_id && isset($wp_query->queried_object) && is_object($wp_query->queried_object) && get_class($wp_query->queried_object) == 'WP_Post') {
         $pid = $wp_query->queried_object_id;
     } else {
         if ($pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id) {
             //hack for static page as home page
             $pid = $wp_query->queried_object_id;
         } else {
             if ($pid === null) {
                 $gtid = false;
                 $maybe_post = get_post();
                 if (isset($maybe_post->ID)) {
                     $gtid = true;
                 }
                 if ($gtid) {
                     $pid = get_the_ID();
                 }
                 if (!$pid) {
                     global $wp_query;
                     if (isset($wp_query->query['p'])) {
                         $pid = $wp_query->query['p'];
                     }
                 }
             }
         }
     }
     if ($pid === null && ($pid_from_loop = TimberPostGetter::loop_to_id())) {
         $pid = $pid_from_loop;
     }
     return $pid;
 }
Ejemplo n.º 2
0
 function testPostCount()
 {
     $posts = $this->factory->post->create_many(8);
     $posts = TimberPostGetter::query_posts('post_type=post');
     $this->assertEquals(8, $posts->post_count());
     $this->assertEquals(8, count($posts));
 }
Ejemplo n.º 3
0
 function testTheLoop()
 {
     for ($i = 1; $i < 3; $i++) {
         $this->factory->post->create(array('post_title' => 'TestPost' . $i));
     }
     $results = Timber::compile('assets/iterator-test.twig', array('posts' => TimberPostGetter::query_posts('post_type=post')));
     $results = trim($results);
     $this->assertStringStartsWith('TestPost2', $results);
     $this->assertStringEndsWith('TestPost1', $results);
 }
Ejemplo n.º 4
0
 /**
  *  If you send the constructor nothing it will try to figure out the current post id based on being inside The_Loop
  * @param mixed $pid
  * @return \TimberPost TimberPost object -- woo!
  */
 function __construct($pid = null)
 {
     if ($pid === null && get_the_ID()) {
         $pid = get_the_ID();
         $this->ID = $pid;
     } else {
         if ($pid === null && ($pid_from_loop = TimberPostGetter::loop_to_id())) {
             $this->ID = $pid_from_loop;
         }
     }
     if (is_numeric($pid)) {
         $this->ID = $pid;
     }
     $this->init($pid);
 }
Ejemplo n.º 5
0
 /**
  *  If you send the constructor nothing it will try to figure out the current post id based on being inside The_Loop
  * @param mixed $pid
  * @return \TimberPost TimberPost object -- woo!
  */
 function __construct($pid = null)
 {
     global $wp_query;
     if ($pid === null && isset($wp_query->queried_object_id) && $wp_query->queried_object_id) {
         $pid = $wp_query->queried_object_id;
         $this->ID = $pid;
     } else {
         if ($pid === null && get_the_ID()) {
             $pid = get_the_ID();
             $this->ID = $pid;
         } else {
             if ($pid === null && ($pid_from_loop = TimberPostGetter::loop_to_id())) {
                 $this->ID = $pid_from_loop;
             }
         }
     }
     if (is_numeric($pid)) {
         $this->ID = $pid;
     }
     $this->init($pid);
 }
Ejemplo n.º 6
0
 /**
  * Is post class or class map.
  *
  * @param string|array $args
  * @return bool
  * @deprecated since 0.20.0
  */
 public static function is_post_class_or_class_map($args)
 {
     return TimberPostGetter::is_post_class_or_class_map($args);
 }
Ejemplo n.º 7
0
 /**
  * WP_Query has posts.
  *
  * @return bool
  * @deprecated since 0.20.0
  */
 static function wp_query_has_posts()
 {
     return TimberPostGetter::wp_query_has_posts();
 }